#!/bin/sh
#
# NOTE:    This script is not configurable!  Any changes made to this
#          script will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#
# Allowed HP-UX exit values:
#	0 = success; causes "OK" to show up in checklist.
#	1 = failure; causes "FAIL" to show up in checklist.
#	2 = skip; causes "N/A" to show up in the checklist.
#           Use this value if execution of this script is overridden
#	    by the use of a control variable, or if this script is not
#	    appropriate to execute for some other reason.
#	3 = reboot; causes the system to be rebooted after execution.
#           This is never called from this script but the documentation
#           is included on allowed HP-UX exit values.
#
# Input and output:
#	stdin is redirected from /dev/null
#
#	stdout and stderr are redirected to the /etc/rc.log file
#	during checklist mode, or to the console in raw mode.

######################################################################
# Automatically create rc*.d symlinks for startup/shutdown
# Use sudo /sbin/chkconfig --add flexlm
# Also --reset option will recreate the links if messed up.
# Syntax     chkconfig levels start-priority stop-priority
# chkconfig: 2345 97 36
# description: init service for flexlm license folder operations
######################################################################
# Author:       Brian Town, Spokane Agilent Technologies
# Modified:     3/9/2001 Sandra Holmgren (user flexcls)
#               This file was sent to the Central License Server team
#               by Brian so we could modify it for our environment.
#               This file is regularly sync'd with the control server
#               at001.cos.agilent.com  via rdist and .rhosts needs to be
#               available.
#               at001:/opt/flexlm/distribution/rc.startups/flexlm.init.d
#		7/7/04 Dawn Hines - Ported to Solaris on sam.cos.agilent.com
#
# Language:     Shell Script
#
# Run Command:  This file is check by the startup/shutdown scripts in init.d
#
#
#
# Description:
# /etc/init.d/flexlm - Starts or stops Flexlm license manager daemons
######################################################################

PATH=/usr/sbin:/usr/bin:/sbin:/bin
export PATH

# NOTE: If your script executes in run state 0 or state 1, then /usr might
#	not be available.  Do not attempt to access commands or files in
#	/usr unless your script executes in run state 2 or greater.  Other
#	file systems typically not mounted until run state 2 include /var
#	and /opt.

hostname=`/bin/hostname`
rval=0

# Check the exit value of a command run by this script.  If non-zero, the
# exit code is echoed to the log file and the return value of this script
# is set to indicate failure.

set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "EXIT CODE: $x"
		rval=1	# script FAILed
	fi
}

# Kill the named process(es).
# $1=<search pattern for your process>

killproc() {
	pid=`ps -el | awk '( ($NF ~ /'"$1"'/) && ($4 != mypid) && ($5 != mypid)  ){ print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill "$pid"; then
			echo "$1 stopped"
		else
			rval=1
			echo "Unable to stop $1"
		fi
	fi
}


case $1 in
'start_msg')
	# Emit a _short_ message relating to running this script with
	# the "start" argument; this message appears as part of the checklist.
	echo "Starting the Flexlm daemons"
	;;

'stop_msg')
	# Emit a _short_ message relating to running this script with
	# the "stop" argument; this message appears as part of the checklist.
	echo "Stopping the Flexlm daemons"
	;;

'start')
	# Execute the commands to start your subsystem
        # Spoof the hostid for DRP
        if ( [ "$hostname" = "drsun" ] &&
             [ -x /opt/flexlm/drp/spoof_hostid ] ); then
          echo "Spoofing hostid for DRP"
          /opt/flexlm/drp/spoof_hostid
        fi

        # Start up the FLEXlm licenses
        /bin/su flexcls -c /opt/flexlm/licenses/start_folders
        set_return
	;;

'stop')
        # Shut down the FLEXlm licenses
        /bin/su flexcls -c /opt/flexlm/licenses/start_folders stop
        set_return
	;;

*)
	echo "usage: $0 {start|stop|start_msg|stop_msg}"
	rval=1
	;;
esac

exit $rval
