#!/bin/sh

# $FreeBSD$
#
# PROVIDE: nrpe2
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable nrpe2:
# nrpe2_enable (bool):    Set to "NO" by default.
#                         Set it to "YES" to enable nrpe2.
# nrpe2_flags (str):      Not set by default.
# nrpe2_configfile (str): Set to "/usr/local/etc/nrpe.cfg" by default.

. /etc/rc.subr

name=nrpe2
rcvar=nrpe2_enable

load_rc_config "${name}"

: ${nrpe2_enable:=NO}
: ${nrpe2_configfile:=/usr/local/etc/nrpe.cfg}

required_files="${nrpe2_configfile}"

command="/usr/local/sbin/nrpe2"
command_args="-c ${nrpe2_configfile} -d"
extra_commands=reload
sig_reload=HUP

start_precmd=nrpe2_prestart
stop_precmd=find_pidfile

find_pidfile()
{
	[ -n "$nrpe2_pidfile" ] &&
	    warn "No longer necessary to set nrpe2_pidfile in rc.conf[.local]"

	if get_pidfile_from_conf pid_file ${nrpe2_configfile}; then
		pidfile="$_pidfile_from_conf"
	else
		pidfile='/var/run/nrpe2/nrpe2.pid'
	fi
}

nrpe2_prestart()
{
	find_pidfile
	install -d -o ${nrpe_user:-nagios} ${pidfile%/*}
	rm -f ${pidfile}
}

run_rc_command "$1"
