#!/bin/sh
#
#
# This script can be used to start and stop the IDL network license
# manager on System V operating systems. To use it, edit it to
# customize it for your site. This is done by modifying the shell
# variable definitions RSI_DIR, IDL_DIR, LM_LICENSE_FILE and
# LOG_FILE_NAME shown below, if necessary.
#
# The licence management software does not require root privileges
# to operate.  The license management daemons should be started
# by a non-privileged user with a restrictive umask setting, preventing
# the unneccessary use of the root account.  The license manager
# can be started by a non-privileged user by modifying the start
# command from below as follows:
#    "start") su username -c "umask 022;$IDL_DIR/bin/lmgrd > $LOG_FILE_NAME &"
# where "username" is the account name of an unprivileged user that has
# execute permission for the license management utilities, write
# permission to create the log file, and read permission for the license file.
#
# Once this file is properly customized, use the following commands to
# install it on your system. These commands assume that your current working
# directory is the one containing this script.  Make sure to use the
# appropriate commands for your system.
#
# Note for HPUX systems, be sure to use /sbin/sh instead of /bin/sh on the 
# first line of the script and uncomment the "PATH" and "export" lines.
# 
# Sun Solaris and SGI IRIX
# ------------------------
#	% cp sys5_idl_lmgrd /etc/init.d
#	% ln /etc/init.d/sys5_idl_lmgrd /etc/rc2.d/S99sys5_idl_lmgrd
#	% ln /etc/init.d/sys5_idl_lmgrd /etc/rc0.d/K01sys5_idl_lmgrd
#
# Compaq Tru64 UNIX
# -----------------
#	% cp sys5_idl_lmgrd /sbin/init.d
#	% ln /sbin/init.d/sys5_idl_lmgrd /sbin/rc3.d/S99sys5_idl_lmgrd
#	% ln /sbin/init.d/sys5_idl_lmgrd /sbin/rc0.d/K01sys5_idl_lmgrd
#
# HP-UX 
# -----
#	% cp sys5_idl_lmgrd /sbin/init.d/idl_lmgrd
#	% ln /sbin/init.d/idl_lmgrd /sbin/rc2.d/S999idl_lmgrd
#	% ln /sbin/init.d/idl_lmgrd /sbin/rc1.d/K100idl_lmgrd
#
# After executing these commands, reboot the system.
#
# The following steps explain the commands above.
#
#	1) Copy this script to the standard System V location.
#	2) Link it into the run level 2 directory (3 for Alpha OSF).
#          The leading 'S' means that our daemon should be started
#          at run level 2 (3 for Alpha OSF). The 99 causes this script
#	   to be executed after all other scripts in the rc directory.
#	3) Link it into the run level 0 directory. The leading 'K' means
#	   that our daemon should be killed when entering run level 0 
#	   (1 for HP-UX).  The 01 causes this script to be executed 
#	   before the other scripts in /etc/rc0.d.
#	4) Reboot the system, returning to multi-user mode. Entering this
#	   mode will cause the IDL license manager daemon to be started.
#
# TO LEARN MORE:
#	- Read about run levels in the System Administration guide for
#	  your system.
#	- Read the file /etc/init.d/README or /sbin/init.d/README or
#         read the manual pages for init, rc0, rc1, rc2, and rc3.

# NOTE: EDIT THESE DEFINITIONS FOR YOUR SITE
VERSION=5.6
RSI_DIR=/usr/local/rsi
IDL_DIR=$RSI_DIR/idl_$VERSION
LM_LICENSE_FILE=$RSI_DIR/license/license.dat
LOG_FILE_NAME="/dev/console"
#PATH=/usr/sbin:/usr/bin:/sbin
#export PATH
# END OF END-USER DEFINITIONS

SCRIPT=$0
export RSI_DIR
export IDL_DIR
export LM_LICENSE_FILE
export PATH


# Make sure we really have the location of the daemon and the license file.
if [ ! -f $IDL_DIR/bin/lmgrd ]; then
  echo "$SCRIPT: Can't find the idl license manager daemon"
  exit 1
fi
if [ ! -f $LM_LICENSE_FILE ]; then
  echo "$SCRIPT: Can't find the idl license file: $LM_LICENSE_FILE"
  exit 1
fi

# Take the desired action
case $1 in
  "start_msg")
        echo "Start IDL license manager (lmgrd)"
        ;;
 
  "stop_msg")
        echo "Stop IDL license manager (lmgrd)"
        ;;
 
  "start") $IDL_DIR/bin/lmgrd > $LOG_FILE_NAME &
           sleep 5  ;;
  "stop")  $IDL_DIR/bin/lmdown -q ;;
  *) echo "$SCRIPT: Unknown option: $1"
     echo "Usage: $SCRIPT { start | stop }"
     exit 1;;
esac

