#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          mcollective
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $remote_fs
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: mcollective init script
# Description:       Starting mcollective deamon
### END INIT INFO
MCOLLECTIVE_BIN=/usr/sbin/mcollectived
MCOLLECTIVE_PID=/var/run/mcollectived.pid
test -x $MCOLLECTIVE_BIN || { echo "$MCOLLECTIVE_BIN not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Check for existence of needed config file and read it
#MCOLLECTIVE_CONFIG=/etc/sysconfig/mcollective
#test -r $MCOLLECTIVE_CONFIG || { echo "$MCOLLECTIVE_CONFIG not existing";
#	if [ "$1" = "stop" ]; then exit 0;
#	else exit 6; fi; }

# Read config	
#. $MCOLLECTIVE_CONFIG

. /etc/rc.status
rc_reset
case "$1" in
    start)
	echo -n "Starting mcollectived "
	/sbin/startproc -f $MCOLLECTIVE_BIN  --pid=${MCOLLECTIVE_PID} --config="/etc/mcollective/server.cfg"
	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down FOO "
	## Stop daemon with killproc(8) and if this fails
	## killproc sets the return value according to LSB.

	/sbin/killproc $MCOLLECTIVE_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    restart)
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    reload)
	## Like force-reload, but if daemon does not support
	## signaling, do nothing (!)

	# If it supports signaling:
	echo -n "Reload service mcollective "
	/sbin/killproc -HUP $MCOLLECTIVE_BIN
	#touch /var/run/FOO.pid
	rc_status -v
	
	## Otherwise if it does not support reload:
	#rc_failed 3
	#rc_status -v
	;;
    status)
	echo -n "Checking for service mcollective "
	/sbin/checkproc $MCOLLECTIVE_BIN
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac
rc_exit
