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

echo "ShutdownAgent"
case "$1" in
    start)
		if [ -e /opt/vmware/vma ]; then
			export LD_LIBRARY_PATH=/opt/vmware/vma/lib64:/opt/vmware/vma/lib
			export PATH=$PATH:/opt/vmware/bin:/usr/java/jre-vmware/bin
			export PERL_LWP_SSL_VERIFY_HOSTNAME=0
		fi
		exist=`/bin/ps x | grep upsagentd | awk '$5 ~ /\x2fupsagentd/ { print $1 }'`
		if [ -n "$exist" ]
		then
			echo "Error : upsagentd is already running."
			exit
		fi
		rm -f /usr/local/upsagent/agent.pid 2>/dev/null
		echo -n "Starting ShutdownAgent(upsagentd) ... "
		/usr/local/upsagent/upsagentd 2>/dev/null
		echo "done."
		;;
    stop)
		echo -n "Stopping ShutdownAgent"
		/usr/local/upsagent/upsagentd stop
		;;
esac
