#!/bin/sh
#
# chkconfig: 2345 31 89
# description: The NUT monitor
# processname: upsmon
# config: /etc/ups/
# pidfile: /var/run/upsmon.pid

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

UPSMON=/sbin/upsmon
LOCKFILE=/var/lock/subsys/upsmon
RETVAL=0

start() {
    action "Starting UPS monitor: " $UPSMON
    RETVAL=$?
    echo
	
    [ "$RETVAL" = 0 ] && touch "$LOCKFILE"
}

stop() {
    echo -n $"Stopping UPS monitor: "
    killproc $UPSMON
    RETVAL=$?
    echo

    [ "$RETVAL" = 0 ] && rm -f "$LOCKFILE"
}

restart() {
	stop
	start
}

# See how we are called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  condstop)
  	if [ -e "$LOCKFILE" ]; then
		stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	    restart
	fi    
	;;
  status)
	status $UPSMON
	;;
  *)
	echo $"Usage: ${0##*/} {start|stop|restart|condstop|condrestart|status}"
	RETVAL=1
esac

exit $RETVAL
