#!/sbin/sh
#
# gated $Revision: 1.2.212.1 $ $Date: 95/10/12 19:33:41 $
#
#           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 dynamic routing daemon"
	;;

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


	if [ "$GATED" -eq 1 -a -x /usr/sbin/gated ] ; then
		/usr/sbin/gated $GATED_ARGS && echo "gated"
		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 [ "$GATED" -ne 1 ] ; then
	    rval=2
        else
            if [ -r /var/run/gated.pid ]; then
                if kill -TERM `cat /var/run/gated.pid`; then
			echo "gated stopped"
		else
			rval=1
			echo "Unable to stop gated"
		fi
	    else
		rval=1
		echo "Unable to stop gated (no pid file)"
	    fi
	fi
        ;;

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

exit $rval


