#!/sbin/sh
#
# 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.
#

#
# Start rbootd
#

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

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


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

stop_msg)
	echo "Stop remote boot daemon"
	;;

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

	if [ 1 -eq 0"$START_RBOOTD" -a -x /usr/sbin/rbootd ]; then
	    if /usr/bin/rtprio 64 /usr/sbin/rbootd $RBOOTD_DEVICES; then
		echo "Remote boot daemon started"
	    else
		set_return
		echo "Could not start remote boot daemon"
    	    fi
	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
	#
#	pid=`ps -ef | awk '$NF~/rbootd/ {print $2}'`
        pid=`ps -el | awk '( ($NF ~ /rbootd/) && ($4 != mypid) && ($5 != mypid)) { print $4 }' mypid=$$ `
	if [ "X$pid" != "X" ]; then
		if kill $pid; then
			echo "Remote boot daemon stopped"
		else
			set_return
			echo "Unable to stop remote boot daemon"
		fi
	fi
	;;

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

exit $rval
