### BEGIN INIT INFO
# apcupsd      This shell script takes care of starting and stopping
#              the apcupsd UPS monitoring daemon.
#
# chkconfig:		2345 60 99
# Provides:		$apcupsd
# Required-Start:      
# Should-Start:		$syslog 
# Required-Stop:       
# Should-Stop:         
# Default-Start:	2 3 4 5
# Default-Stop:		0 1  6
# Short-Description:	UPS monitor
# Description:		apcupsd monitors power and takes action if necessary
### END INIT INFO

. /lib/lsb/init-functions

PROG="apcupsd"
BIN_FILE="/usr/sbin/$PROG"
APCPID=/var/run/w$PROG.pid

case "$1" in
   start)
      rm -f /etc/$PROG/powerfail
      rm -f /etc/nologin
      log_info_msg "Starting UPS monitoring..."
      start_daemon ${BIN_FILE} -f /etc/$PROG/$PROG.conf
      RETVAL=$?
      evaluate_retval
      if [ ${RETVAL} -eq 0 ] ; then
	touch /var/lock/subsys/$PROG
	fi
      ;;

   stop)
      log_info_msg "Shutting down UPS monitoring:"
      killproc ${BIN_FILE}
      evaluate_retval
      rm -f $APCPID
      rm -f /var/lock/subsys/$PROG
      ;;

   restart)
      $0 stop
      sleep 15
      $0 start
      ;;

   status)
      statusproc ${BIN_FILE}
      RETVAL=$?
      if [ $RETVAL -eq 0 ]
       then
          /usr/sbin/apcaccess status
       else
          exit $RETVAL
       fi

      ;;

   *)
      echo "Usage: $0 {start|stop|restart|status}"
      exit 1
      ;;
esac
exit 0
