#!/usr/bin/bash
# 
#set -x
# chkconfig: 345 99 01
# description: OpMon network monitor
#
# File : opmonconnector
#

# Source function library
# Solaris doesn't have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
	. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
	. /etc/init.d/functions
fi

prog=opmonconnector
prefix=/usr/local/opmon
exec_prefix=${prefix}
NagiosBin=${exec_prefix}/bin/opmonconnector
NagiosRunFile=/usr/local/opmon/var/opmonconnector.lock
NagiosLockDir=/var/lock/subsys
NagiosLockFile=${NagiosLockDir}/opmonconnector
          

# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
    echo "Executable file $NagiosBin not found.  Exiting."
    exit 1
fi

# See how we were called.
case "$1" in

	start)
		echo -n "Starting $prog"

	        daemon --pidfile=${NagiosRunFile} $NagiosBin
       		RETVAL=$?
		echo
        	[ $RETVAL = 0 ] && touch ${NagiosLockFile}
		;;

	stop)
		echo -n $"Stopping $prog: "
		killproc /usr/local/opmon/bin/opmonconnector >/dev/null 2>/dev/null
		RETVAL=$?
		if [[ $RETVAL == 0 ]]; then
			success	
		else
			echo -n "already stopped"
		fi
		echo
		[ $RETVAL = 0 ] && rm -f /var/lock/subsys/opmonconnector ${NagiosRunFile}
		;;

	status)
		status -p ${NagiosRunFile} $prog
		RETVAL=$?
		;;
	restart)
		$0 stop
		$0 start
		;;

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

esac

exit $RETVAL
  
# End of this script
