#!/bin/sh
#
# (c) Copyright 2002 Hewlett-Packard Development Company, L.P.
#
# See "man chkconfig" for information on next two lines (Red Hat only)
# chkconfig: 2345 92 1
# description: hp SNMP Agents. 
#
#
# Following lines are in conformance with LSB 1.2 spec
### BEGIN INIT INFO
# Provides:            hp-snmp-agents
# Required-Start:      hp-health snmp
# Required-Stop:       
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Description:         starts hp SNMP Agents
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME="hp Proliant SNMP Agents"

DEP="hpasmd hpasmxld hpasmlited hpasmpld"
DEPSCRIPT=/etc/init.d/hp-health

SERVERSCRIPTS="\
/opt/hp/hp-snmp-agents/server/etc/cmahealthd \
/opt/hp/hp-snmp-agents/server/etc/cmastdeqd \
/opt/hp/hp-snmp-agents/server/etc/cmahostd \
/opt/hp/hp-snmp-agents/server/etc/cmathreshd \
/opt/hp/hp-snmp-agents/server/etc/cmasm2d \
/opt/hp/hp-snmp-agents/server/etc/cmarackd \
/opt/hp/hp-snmp-agents/server/etc/cmaperfd \
/opt/hp/hp-snmp-agents/server/etc/cmapeerd \
"

STORAGESCRIPTS="\
/opt/hp/hp-snmp-agents/storage/etc/cmaeventd \
/opt/hp/hp-snmp-agents/storage/etc/cmafcad \
/opt/hp/hp-snmp-agents/storage/etc/cmasasd \
/opt/hp/hp-snmp-agents/storage/etc/cmaidad \
/opt/hp/hp-snmp-agents/storage/etc/cmaided \
/opt/hp/hp-snmp-agents/storage/etc/cmascsid \
"

NICSCRIPTS="\
/opt/hp/hp-snmp-agents/nic/etc/cmanicd \
"

export CMAINCLUDE="/opt/hp/hp-snmp-agents/server/etc/cmad"

case "$1" in
   start)
      RC=0;
      if [ -z "`pidof $DEP`" ]; then 
	 if [ -f ${DEPSCRIPT} ]; then
         	$DEPSCRIPT start
         	RC=$?
	 fi
         echo
      fi
      if [ "$RC" -ne "0" ]; then
         echo "$DEPSCRIPT: failed to start! Please review log file for details."
         echo "The log file locations are documented in the hp-health(4) man page."
         echo
         exit $RC
      fi
      for SCRIPT in $SERVERSCRIPTS $STORAGESCRIPTS $NICSCRIPTS; do
         if [ -x $SCRIPT ]; then
            sh $SCRIPT start
         fi
      done
      [ -f /etc/redhat-release ] && touch /var/lock/subsys/hp-snmp-agents
      grep "cmaX" /etc/snmp/snmpd.conf > /dev/null 
      if [ $? -ne "0" ]; then 
         echo "WARNING:hp-snmp-agents is not configured."
         echo "You must type '/sbin/hpsnmpconfig' as 'root' user to configure agents."
      fi
   ;;
   stop)
      for SCRIPT in  $NICSCRIPTS $STORAGESCRIPTS $SERVERSCRIPTS; do
         if [ -x $SCRIPT ]; then
            sh $SCRIPT stop
         fi
      done
      [ -f /etc/redhat-release ] && rm -rf /var/lock/subsys/hp-snmp-agents
   ;;
   restart)
      $0 stop
      sleep 5
      $0 start
   ;;
   status)
      for SCRIPT in $SERVERSCRIPTS $STORAGESCRIPTS $NICSCRIPTS; do
         if [ -x $SCRIPT ]; then
            sh $SCRIPT status
         fi
      done
      grep "cmaX" /etc/snmp/snmpd.conf > /dev/null 
      if [ $? -ne "0" ]; then 
         echo "WARNING:hp-snmp-agents is not configured."
         echo "You must type '/sbin/hpsnmpconfig' as 'root' user to configure agents."
      fi
   ;;
   *)
     echo "Usage: /etc/init.d/hp-snmp-agents {start|stop|restart|status}"
     exit 1
esac

exit 0 
