#!/sbin/sh
#
# @(#) $Revision: 78.1 $
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt 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.
#

#
# Environment daemon
#

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

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "ERROR CODE $x"
		rval=1
	fi
}

case $1 in
start_msg)
	echo "Start environment monitoring daemon"
	;;

stop_msg)
	echo "Stop environment monitoring daemon"
	;;

'start')
	if [ -f /etc/rc.config.d/envd ] ; then
		. /etc/rc.config.d/envd
	else
		echo "ERROR: /etc/rc.config.d/envd defaults file MISSING"
	fi
	
	if [ "$ENVD" -eq 1 -a -x /usr/sbin/envd -a -f /etc/envd.conf ]; then
		if /usr/sbin/envd; then
			echo "Environmental daemon started"
		else
			set_return
		fi
	else
		rval=2
	fi

	;;

'stop')
	#
	# Determine PID of process(es) to stop
	#
	pid=`ps -el | awk '( ($NF ~ /envd/) && ($4 != mypid) && ($5 != mypid)  ){ print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "envd stopped"
		else
			set_return
			echo "Unable to stop envd"
		fi
	fi

	;;

*)
	echo "usage: $0 {start|stop}"
	;;
esac

exit $rval
