#!/bin/sh

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

. /etc/rc.subr

name=nrpe3
rcvar=nrpe3_enable

load_rc_config "${name}"

: ${nrpe3_enable:=NO}
: ${nrpe3_configfile:=/usr/local/etc/nrpe.cfg}

required_files="${nrpe3_configfile}"

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

start_precmd=nrpe3_prestart
stop_precmd=find_pidfile

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

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

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

run_rc_command "$1"
