#!/bin/sh
#
# chkconfig: 2345 10 90
# description: The ups daemon automatically starts a shutdown
# processname: upsd
# config: /etc/ups/

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

# Get config.
. /etc/sysconfig/ups

# Check x is up.

# See how we are called.
case "$1" in
  start)
	if [ "$HOST" = "localhost" ]; then
	    echo -n "Starting $MODEL: "
	    daemon /usr/bin/$MODEL $OPTIONS $DEVICE 
	    echo ""

	    echo -n "Starting UPS daemon: "
	    daemon /usr/bin/upsd
	    echo ""

	    echo -n "Starting UPS monitor (master): "
	    daemon /usr/bin/upsmon $HOST master
	    echo ""
	else
	    echo -n "Starting UPS monitor (slave): "
	    daemon /usr/bin/upsmon $HOST slave
	    echo ""
	fi

	touch /var/lock/subsys/ups
	;;
  stop)
	echo -n "Stopping UPS monitor: "
	killproc upsmon
	echo ""

	if [ "$HOST" = "localhost" ]; then
	    echo -n "Shutting down UPS daemon: "
	    killproc upsd
	    echo ""

	    echo -n "Shutting down $MODEL: "
	    killproc $MODEL
	    echo ""
	fi
	rm -f /var/lock/subsys/ups
	;;
  restart)
	$0 stop
	$0 start
	;;
  status)
	if [ "$HOST" = "localhost" ]; then
	    status upsd
	    status $MODEL
	fi
	status upsmon
	;;
  *)
	echo "Usage: ups {start|stop|restart|status}"
	exit 1
esac

