#!/usr/bin/sh
# 
# chkconfig: 345 99 01
# description: opdiscovery startup script  
#
# File : opdiscovery
#

. /etc/rc.d/init.d/functions

PIDFILE="/var/run/opdiscovery.pid"

stop () {
	PID=`cat $PIDFILE 2>/dev/null`
	PID=`/bin/echo -n $PID`
	RUNNING=`/bin/ps $PID | /bin/grep opdiscovery.php | /usr/bin/wc -l`
	if [ $RUNNING -eq "1" ]; then
		PID=`cat $PIDFILE 2>/dev/null`
		PID=`/bin/echo -n $PID`
		/bin/kill -9 $PID 2>/dev/null
		/bin/kill -9 $PID 2>/dev/null
		/bin/kill -9 $PID 2>/dev/null
	else
		echo "opdiscovery.php currently stopped"
	fi
}

start () {
	PID=`cat $PIDFILE 2>/dev/null`
	PID=`/bin/echo -n $PID`
	RUNNING=`/bin/ps $PID | /bin/grep opdiscovery.php | /usr/bin/wc -l`
	if [ $RUNNING -ne "1" ]; then
		/usr/local/opmon/utils/opdiscovery.php -d >/dev/null 2>&1 &
	fi
	exit 0
}

case "$1" in

	start)
		echo "Starting opdiscovery"
		start;
		;;

	stop)
		echo "Stopping opdiscovery"
		stop;
		exit 0
		;;

	status)
		status opdiscovery.php
		exit $?
		;;

	*)
		echo "Usage: opdiscovery {start|stop|status}"
		exit 1
		;;

esac
  
# End of this script
