#!/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=lmd
prefix=/usr/local/opmon
exec_prefix=${prefix}
NagiosBin=${exec_prefix}/bin/lmd
NagiosRunFile=/usr/local/opmon/var/lmd.lock
NagiosLockDir=/var/lock/subsys
NagiosLockFile=${NagiosLockDir}/lmd
          

# 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} nohup $NagiosBin --config=/etc/lmd/lmd.ini --pidfile=${NagiosRunFile} >/dev/null 2>/dev/null &
	        $NagiosBin --config=/etc/lmd/lmd.ini --pidfile=${NagiosRunFile} >/dev/null 2>/dev/null &
       		RETVAL=$?
		echo
        	[ $RETVAL = 0 ] && touch ${NagiosLockFile}
	;;

	stop)
		echo -n $"Stopping $prog: "
		killproc /usr/local/opmon/bin/lmd >/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/lmd ${NagiosRunFile}
		;;

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

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

esac

exit $RETVAL
  
# End of this script
