#! /bin/bash
# Platform: Linux
# Description: Start upsentryd when OS boots.
### BEGIN INIT INFO
# Provides:            UPSentry2012
# Required-Start:      
# Required-Stop:       
# Default-Start:       3 5
# Default-Stop:        0 1 2 6
# Short-Description:   UPSentry2012, the UPS Shutdown Service
# Description:         Start UPSentry2012 to provide the unattended
#	shutdown service with the UPS.
### END INIT INFO

echo "UPSentry2012"
case "$1" in
    start)
		exist=`/bin/ps x | grep upsentryd | awk '$5 ~ /\x2fupsentryd/ { print $1 }'`
		if [ -n "$exist" ]
		then
			echo "Error : upsentryd is already running."
			exit
		fi
		rm -f /usr/local/upsentry/service.pid 2>/dev/null
		echo -n "Starting UPSentry 2012(upsentryd) ... "
		/usr/local/upsentry/upsentryd 2>/dev/null
		echo "done."
		;;
    stop)
		echo -n "Stopping UPSentry 2012"
		/usr/local/upsentry/upsentryd stop
		;;
esac
