freebsd-ports/net-mgmt/icinga/files/icinga.in
Lars Engels c48568fe53 - Add an alias to checkconfig': configtest'
The former is what is used in the upstream init script, the latter is commonly used in
  our rc scripts.
- Bump PORTREVISION

Suggested by:	demon
Feature safe:	yes
2012-10-20 12:58:17 +00:00

125 lines
2.7 KiB
Bash

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: icinga
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable icinga:
# icinga_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable icinga.
# icinga_precache (bool): Set to "NO" by default.
# Set it to "YES" to enable pre-caching.
# icinga_flags (str): Set to "" by default.
# icinga_configfile (str): Set to "%%PREFIX%%/etc/icinga/icinga.cfg" by default.
#
. /etc/rc.subr
name="icinga"
rcvar=icinga_enable
load_rc_config "${name}"
: ${icinga_enable:="NO"}
: ${icinga_configfile="%%PREFIX%%/etc/icinga/icinga.cfg"}
: ${icinga_precache:="NO"}
command="%%PREFIX%%/bin/icinga"
command_args="-d"
extra_commands="reload checkconfig configtest"
pidfile="%%ICINGADIR%%/icinga.lock"
icinga_user="%%ICINGAUSER%%"
icinga_group="%%ICINGAGROUP%%"
icinga_logfile="%%ICINGALOGDIR%%/${name}.log"
icinga_statusfile="%%ICINGADIR%%/status.sav"
icinga_cmdfile="%%ICINGADIR%%/rw/${name}.cmd"
start_cmd="start_cmd"
checkconfig_cmd="icinga_checkconfig verbose"
configtest_cmd="${checkconfig_cmd}"
start_precmd="start_precmd"
stop_postcmd="stop_postcmd"
restart_precmd="icinga_checkconfig"
reload_precmd="reload_precmd"
sig_reload=HUP
required_files="${icinga_configfile}"
command_args="${command_args} ${icinga_configfile}"
icinga_cacheconfig() {
if ! checkyesno icinga_precache; then
return 0
fi
echo -n "Pre-Caching icinga configuration: "
${command} -pv ${icinga_configfile} 2>&1 >/dev/null
if [ $? != 0 ]; then
echo "FAILED"
${command} -v ${icinga_configfile}
return 1
else
command_args="-u -x ${command_args}"
echo "OK"
fi
}
icinga_checkconfig() {
echo -n "Performing sanity check of icinga configuration: "
if [ "$1" != "verbose" ]; then
${command} -v ${icinga_configfile} 2>&1 >/dev/null
else
${command} -v ${icinga_configfile}
fi
if [ $? != 0 ]; then
echo "FAILED"
${command} -v ${icinga_configfile}
return 1
else
echo "OK"
fi
}
reload_precmd() {
if ! icinga_checkconfig; then
return 1
fi
if ! icinga_cacheconfig; then
return 1
fi
}
start_precmd() {
if ! icinga_checkconfig; then
return 1
fi
if ! icinga_cacheconfig; then
return 1
fi
if [ ! -f "${icinga_logfile}" ]; then
install -o "${icinga_user}" -g "${icinga_group}" -m 644 /dev/null "${icinga_logfile}"
fi
if [ ! -f "${icinga_statusfile}" ]; then
install -o "${icinga_user}" -g "${icinga_group}" -m 644 /dev/null "${icinga_statusfile}"
fi
rm -f "${icinga_cmdfile}"
}
stop_postcmd() {
rm -f "%%ICINGADIR%%/icinga.tmp" "${icinga_cmdfile}"
}
start_cmd() {
${command} ${command_args}
}
run_rc_command "$1"