#!/sbin/sh
#
# rwhod $Revision: 1.2.212.2 $ $Date: 95/12/26 10:04:46 $
#
#           Copyright (C) 1993, 1994 Hewlett-Packard Company
#
# 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.
#

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

rval=0
set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # always 1 so that 2 can be used for other reasons
        fi
}


case $1 in
start_msg)
	echo "Start remote system status daemon"
	;;

stop_msg)
	echo "Stopping remote system status daemon"
	;;
'start')
	if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
	else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi

	if [ "$RWHOD" -eq 1 ]; then
		/usr/sbin/rwhod && echo "rwhod"
		set_return
	else
		rval=2
	fi
	;;

'stop')
	if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
	else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi

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

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

exit $rval
