#!/bin/sh
# 
# Copyright 2000 American Power Conversion, All Rights Reserved
#
# Revision History:
#  msamson  01Apr99: For Linux, we have to remove upsoff.cmd, because we 
#                    cannot remove this file once all filesystems have 
#                    been unmounted in our shutdown script. 
#  msamson  04Oct99: Incorporated standard init fixes from Redhat 
#                    (pjones@redhat.com)
#  msamson  19Jan00: Moved "rm -f /upsoff.cmd" call inside start case
#  mcondor  26Jan2001: updated version to 4.5.3
# chkconfig: 2345 98 92
# description: Uninterruptable Power Supply Monitoring Daemon
#
#

if [ -f /etc/redhat-release ]; then
  . /etc/rc.d/init.d/functions
fi

INSTALL_PATH="/usr/lib/powerchute"

if [ -f /etc/redhat-release ]; then
	RETVAL=$? 
fi

case "$1" in
start)
	
	if [ -r /upsoff.cmd ]
	then
	    rm -f /upsoff.cmd
	fi
	
	cd $INSTALL_PATH
	./upsd   2>/dev/null
	if [ -f /etc/redhat-release ]; then
		RETVAL=$?
	  	action "PowerChute Plus for UNIX, v4.5.3: Copyright (c) 2001, American Power Conversion" /bin/true
	  	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/upsd 
	else 
	  	echo
	  	echo "PowerChute Plus for UNIX, v4.5.3: Copyright (c) 2001, American Power Conversion "
	  	echo
	fi
	;;
stop)
	if [ -f /etc/redhat-release ]; then
	  	echo -n "Shutting down upsd: "
	  	killproc _upsd
	  	rm -f /var/lock/subsys/upsd
		echo
	fi
	;;
reload|restart)
	if [ -f /etc/redhat-release ]; then
		if [ ! -f /var/lock/subsys/upsd ]; then
			echo "upsd not running"
			exit 1
		fi
		$0 stop
		$0 start
	fi
	;;
status)
	if [ -f /etc/redhat-release ]; then
		status _upsd
	fi
	;;
*)
	if [ -f /etc/redhat-release ]; then
		echo "*** Usage: upsd {start|stop|status|restart}"
		exit 1
	else 
		echo "Usage upsd [start|stop]"
	fi
	;;
esac

if [ -f /etc/redhat-release ]; then
	exit $RETVAL
fi




















