#!/bin/bash
#
# ups-belkin    This shell script takes care of starting and stopping
#               Belkin's UPS daemon.
#
# chkconfig: 345 70 30
# description: upsd is a daemon for monitoring a Belkin UPS.
# processname: upsd
# config: /etc/upsd.path
# pidfile: [install-dir]/UPSD.PID

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

# Source upsd configureation.
if [ -f /etc/upsd.path ] ; then
         BELKIN=`cat /etc/upsd.path`
fi

start() {
         # Start daemons.
         echo -n $"Starting ups-belkin: "
         rm -f $BELKIN/UPSD.PID    2>/dev/null
         daemon --user=ups $BELKIN/upsd
         RETVAL=$?
         echo
         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ups-belkin
         return $RETVAL
}

stop() {
         # Stop daemons.
         echo -n $"Shutting down ups-belkin: "
         killproc upsd
         RETVAL=$?
         echo
         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ups-belkin
         return $RETVAL
}

# See how we were called.
case "$1" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   status)
         status upsd
         RETVAL=$?
         ;;
   restart|reload)
         stop
         start
         RETVAL=$?
         ;;
   condrestart)
         if [ -f /var/lock/subsys/ups-belkin ]; then
             stop
             start
             RETVAL=$?
         fi
         ;;
   *)
         echo $"Usage: $0 {start|stop|restart|condrestart|status}"
         exit 1
esac

exit $RETVAL
