#!/bin/bash 

# Bring up/down snmpd

SETSID=/usr/bin/setsid
if [ -z "$RC_CONF" ] ; then
	. /etc/sysconfig/rc.conf
fi

if [ -z "$NET_FUNCS" ] ; then
	. /bin/network-functions
fi

PIDFILE="/var/run/snmpd.pid"
SERVICE=snmpd
SNMPD_CONF=/etc/fiad-conf/net-snmp/snmpd.conf

do_start ()
{
	if ! ServiceCheckRunning1 ; then
		return $?
	fi

	$SETSID /bin/snmpd -c $SNMPD_CONF -p $PIDFILE 
	/bin/sleep 2

	return $?
}

do_stop ()
{
	ServiceStop

	return $?
}


do_status ()
{
	ServiceStatus 
	
	return $?
}

case "$1" in
	start)
		do_start
		/bin/sleep 2
		/etc/init.d/trapagent start
		/etc/init.d/subagent start
		ServiceCheckRunning2
		;;
	stop)
		/etc/init.d/trapagent stop
		/etc/init.d/subagent stop
		/bin/sleep 1
		do_stop
		;;
	status)
	if  [ "$START_SNMP" = "false" ] ; then
		exit 0
	fi
	
		do_status
		if [ $? = "1" ]; then
		    exit 1
		fi
		/etc/init.d/trapagent status
		if [ $? = "1" ]; then
		    exit 1
		fi
		/etc/init.d/subagent status
		if [ $? = "1" ]; then
		    exit 1
		fi
		;;
	restart)
		$0 stop
		$0 start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit $?
