#! /sbin/sh
#
# chkconfig: - 55 45
# description:	The UPSMON daemon control the UPS
#
# processname: upsagent

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

prog="upsagent"
rval=0

set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1
        fi
} 

# See how we were called.
case "$1" in
start_msg)
	echo "Start UPS monitoring daemon"
	;;

stop_msg)
	echo "Stop UPS monitoring daemon"
	;;
 
'start')
    if [ -f /opt/upsmon/upsmon.ini ] 
    then
	   /opt/upsmon/upsagent >/dev/console 2>&1
	   #/opt/upsmon/upsagent	
	   echo "UPS daemon started"
	   #sleep 2
    else
       echo "ERROR: /opt/upsmon/upsmon.ini configuration file missing"
	   exit 1
    fi 
	;;

'stop')
	for PROC in `ps -e|grep 'upsagent'|grep -v grep|tr -s ' '|cut -d' ' -f2`
	do	kill -15 $PROC
	done
	echo  "UPS daemon stopped"
	;;

*)
	echo "Usage: $0 {start|stop|start_msg|stop_msg}"
	rval=1
esac

exit $rval
