#!/bin/bash
#
#       /etc/rc.d/init.d/upsagent
#
# chkconfig: 2345 70 20
# description: upsagent is talking to upsman and makes \
#   information available over snmp.
# processname: upsagent

# Source function library.
. /etc/rc.d/init.d/functions

PATH=/usr/ups:$PATH
UPSAGT_STANDALONE=
UPSAGT_PORT=

# upsagent may be run either in standalone or agentx mode.
# If you do not have allready a snmp daemon running as an agentx master
# you may uncomment the following line.
# UPSAGT_STANDALONE=1

# If you have a snmp daemon running which is not capable of
# being an agentx master, the default snmp port(161) may be allready 
# in use. Uncomment the following line to run upssnmpd on a different port.
# UPSAGT_PORT=1161

test -x /usr/ups/upsagent || exit 0

export PATH UPSAGT_STANDALONE UPSAGT_PORT
# export UPSAGT_CONF=/usr/ups/upsagent.conf


case "$1" in
    start)
        echo -n "Starting upsagent: "
	cd /usr/ups
        daemon upsagent
	echo
        touch /var/lock/subsys/upsagent
        agent_retry 1 5 &
        ;;
    stop)
        echo -n "Shutting down upsagent: "
        killproc upsagent
	echo
        rm -f /var/lock/subsys/upsagent
        test -e /var/run/agent_retry.pid && { kill `head -1 /var/run/agent_retry.pid`; rm -f /var/run/agent_retry.pid; }
        ;;
    status)
	status upsagent
        ;;
    restart)
	# $0 stop
        echo -n "Shutting down upsagent: "
        killproc upsagent
	echo
        rm -f /var/lock/subsys/upsagent
        test -e /var/run/agent_retry.pid && { kill `head -1 /var/run/agent_retry.pid`; rm -f /var/run/agent_retry.pid; }
	# $0 start
        echo -n "Starting upsagent: "
	cd /usr/ups
        daemon upsagent
	echo
        touch /var/lock/subsys/upsagent
        agent_retry 1 5 &
        ;;
    reload)
	# $0 stop
        echo -n "Shutting down upsagent: "
        killproc upsagent
	echo
        rm -f /var/lock/subsys/upsagent
        test -e /var/run/agent_retry.pid && { kill `head -1 /var/run/agent_retry.pid`; rm -f /var/run/agent_retry.pid; }
	# $0 start
        echo -n "Starting upsagent: "
	cd /usr/ups
        daemon upsagent
	echo
        touch /var/lock/subsys/upsagent
        agent_retry 1 5 &
        ;;
    *)
        echo "usage: upsagent { start | stop | status | reload | restart }"
        exit 1
        ;;
esac



