#!/usr/bin/sh
#
# chkconfig: 345 99 01
# description: start inicital discovery on network lan address
#
# File : opdiscovery
#

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

PIDFILE="/var/run/start-initial-discovery.pid"

stop () {
    echo "Not implemented"
}

start () {
	OPDISCOVERY=`/bin/ps $PID | /bin/grep opdiscovery.php | /bin/grep -v grep | /usr/bin/wc -l`
	GEARMAN=`/bin/ps $PID | /bin/grep gearmand | /bin/grep -v grep | /usr/bin/wc -l`
    RUNNING=($OPDISCOVERY + $GEARMAN)
	if [ $RUNNING -ne "2" ]; then
		/usr/bin/php /usr/local/opmon/utils/startinitialdiscovery.php >/dev/null 2>&1 &
	fi
	exit 0
}

case "$1" in

	start)
		echo "Starting initial discovery"
		start;
		;;

	stop)
		echo "Stopping initial discovery"
		stop;
		exit 0
		;;

	status)
		status startinitialdiscovery.php
		exit $?
		;;

	*)
		echo "Usage: start-initial-discovery {start}"
		exit 1
		;;

esac
# End of this script
