#!/bin/sh
#
#chkconfig:35 99 1
#
#description: ShutdownWizard service
#
MONITOR_HOME=#MONITOR_HOME
UPS_PORT=#UPS_PORT
pids=$(netstat -lnp | grep $UPS_PORT | awk '{print $7}')
pids=${pids%/*}
case $1 in

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

	stop)
		if [ -n "$pids" ]; then
			echo "ShutdownWizard service is stopping..."
			cd $MONITOR_HOME
			./StopConsole &
		else 
			echo "ShutdownWizard servcie has already stopped"
		fi
		exit 1
	;;
	
	restart)
		cd $MONITOR_HOME
		./StopConsole &
		sleep 5
		cd $MONITOR_HOME
		./StartConsole &
		echo "ShutdownWizard service is restarting..."
		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
