#!/bin/sh

cd /usr/local/controller/scripts

case "$1" in
	start)
		if [ "$(ps x | grep -v grep | grep -c connector)" -gt "0" ]
		then
		    if [ "$(ps x | grep -v grep | grep -c mysqlconn.pl)" -gt "0" ]
			then
			    echo -n "polling stop; "
			    ./pmanager.sh stop
		    fi
		    echo -n "polling start; "
		    ./pmanager.sh start
		else
		    sleep 1
		    if [ "$(ps x | grep -v grep | grep -c connector)" -gt "0" ]
		    then 
			echo -n "polling start; "
			./pmanager.sh start
		    else
		    echo "no connector detected."
		    echo "please, start connector first."
		    fi
		fi
		;;
	stop)
		echo -n "polling stop; "
		./pmanager.sh stop
		;;
	restart)
		echo "polling restart; "
		./pmanager.sh stop
		sleep 1
		./pmanager.sh start
		;;
	*)
		echo ""
		echo "Usage: `basename $0` { start | stop }"
		echo ""
		;;
esac

exit 0
