#!/bin/sh
# $Id: template,v 1.3 2003/05/21 17:47:00 ldv Exp $
#
# nrpe		Nagios(R) Remote Plugin Execution daemon
#
# chkconfig: - 90 10
# description:	Daemon for executing check-commands, \
#               received from remote Nagios(R) daemon, \
#               and send result back via network.
# processname: nrpe
# config: /etc/nagios/nrpe.conf

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

DAEMON=/usr/sbin/nrpe
CONFIG=/etc/nagios/nrpe.conf

LOCKFILE=/var/lock/subsys/nrpe
RETVAL=0

start()
{
	start_daemon --lockfile "$LOCKFILE" --expect-user nagios -- "$DAEMON" -c "$CONFIG" -d
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" --expect-user nagios -- nrpe
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading nrpe
	#stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- template
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --expect-user nagios -- nrpe
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
