#!/bin/sh
#
#chkconfig:35 99 1
#
#description: Shutdown_Wizard service
#
MONITOR_HOME=/usr/local/ShutdownWizard

UPS_PORT=31234

pids=$(netstat -lnp | grep $UPS_PORT | awk '{print $7}')
pids=${pids%/*}
export DISPLAY=:0.0

case $1 in

	start)
		if [ -n "$pids" ]; then
			echo "ShutdownWizard service already start"
		else 
			cd $MONITOR_HOME
			./ShutdownWizard &
			echo "start ShutdownWizard servcie "
		fi
		exit 1
	;;

	stop)
		if [ -n "$pids" ]; then
			echo "stop ShutdownWizard service "
			cd $MONITOR_HOME
			./StopConsole &
		else 
			echo "ShutdownWizard servcie already stop"
		fi
		exit 1
	;;
	
	restart)
		cd $MONITOR_HOME
		./StopConsole &
		sleep 5
		cd $MONITOR_HOME
		./ShutdownWizard &
		exit 1
	;;

	status)
		if [ -n "$pids" ]; then
			echo "ShutdownWizard is running "
		else 
			echo "ShutdownWizard is not run "
		fi
	;;

*)
	echo "Usage:$0{start|stop|restart}"
	exit 1
esac
