#!/sbin/sh
#
# FILE:		/sbin/init.d/ospfmib
#
# 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.
#
# PURPOSE:
#	Start the the OSPPF MIB subAgent (ospfagt).
#	Note to restart the subAgent manually after the system is up see 
#	/usr/sbin/snmpd, /usr/sbin/sugagt_ld and /usr/sbin/sugagt_unld.
#
# Allowed 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. 

# 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.

# WARNING: If this script (or any other startup 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 it executes in run state 2 or greater.
#	Other file systems typically not mounted until run state 2 include /var
#	and /opt.


###############################################################################


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 OSPF MIB Network Management subAgent"
     ;;

  stop_msg)
     echo "Stopping OSPF MIB Network Management subAgent"
     ;;

  'start')
     if [ -f /etc/rc.config ] ; then	# Source configuration variables
       . /etc/rc.config			# Get all of them just in case.
     else
       echo "ERROR: /etc/rc.config defaults file MISSING"
     fi

     pid=`ps -e | awk '$NF~/gated/ {print $1}'`
     if [ "$GATED" -eq 0 -a "X$pid" = "X" ] ; then
             echo "WARNING: gated needs to be started"
     fi

     if [ "${OSPFMIB:-}" = "0" ] ; then
             rval=2   # Skip per user configuration
     else
             eval /usr/sbin/ospfagt ${OSPFMIB_ARGS:-} &
             set_return
     fi
     ;;

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

     if [ "$OSPFMIB" -ne 1 ] ; then
            if [ -r /usr/sbin/ospfagt ]; then
                 rval=2
            fi
     else
            if [ -r /usr/sbin/ospfagt ]; then
                if kill -TERM `ps -e | grep ospfagt`; then
                        echo "ospfagt stopped"
                else
                        rval=1
                        echo "Unable to stop ospfagt"
                fi
            else
                rval=1
                echo "Unable to stop ospfagt"
            fi
       fi
       ;;
*)
     echo "usage: $0 {start|stop|start_msg|stop_msg}"
     rval=1
     ;;
esac

exit $rval

