#!/bin/sh
#
# ups		NUT - Network UPS Tools daemon
#
# chkconfig:	2345 10 90
#
# description:	The ups daemon monitors an UPS and makes information about
#               it's status available to other programs
# processname:	upsd
# config:	/etc/ups/

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

# Get network config
. /etc/sysconfig/network

# Get config.
[ -f /etc/sysconfig/ups ] && . /etc/sysconfig/ups

[ -n "$PORT" ] && OPTIONS="-p $PORT"
[ -n "$TCP_PORT" ] && OPTIONS="-t $TCP_PORT"
[ -n "$BIND_ADDRESS" ] && OPTIONS="$OPTIONS -i $BIND_ADDRESS"

prog0="UPS Drivers"
prog1="UPS Network Daemon"

# See how we are called.
case "$1" in
  start)
	echo -n $"Starting $prog0: "
	daemon /usr/lib/nut/upsdrvctl start
	echo
	echo -n $"Starting $prog1: "
	daemon "upsd $OPTIONS"
	RETVAL=$?
	touch /var/lock/subsys/ups
	echo
	;;
  stop)
	echo -n $"Stopping $prog1: "
	killproc upsd
	RETVAL=$?
	echo
	echo -n $"Stopping $prog0: "
	/usr/lib/nut/upsdrvctl stop >/dev/null
	[ $RETVAL -ne 0 ] && failure $"$base stop"
 	[ $RETVAL -eq 0 ] && success $"$base stop"
	rm -f /var/lock/subsys/ups
	echo
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	daemon upsd -c reload
  	;;
  status)
	status upsd
	/usr/lib/nut/upsdrvctl status
	;;
  *)
	msg_Usage "$0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac 
exit $RETVAL
