summaryrefslogtreecommitdiff
path: root/net-mgmt/icinga-core/files/icinga.in
diff options
context:
space:
mode:
Diffstat (limited to 'net-mgmt/icinga-core/files/icinga.in')
-rw-r--r--net-mgmt/icinga-core/files/icinga.in141
1 files changed, 141 insertions, 0 deletions
diff --git a/net-mgmt/icinga-core/files/icinga.in b/net-mgmt/icinga-core/files/icinga.in
new file mode 100644
index 000000000000..d7ccf2cc5d77
--- /dev/null
+++ b/net-mgmt/icinga-core/files/icinga.in
@@ -0,0 +1,141 @@
+#!/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"
+icinga_user="%%ICINGAUSER%%"
+icinga_group="%%ICINGAGROUP%%"
+
+icinga_dir="%%ICINGADIR%%"
+icinga_logdir="%%ICINGALOGDIR%%"
+
+pidfile="${icinga_dir}/icinga.lock"
+icinga_logfile="${icinga_logdir}/${name}.log"
+icinga_statusfile="${icinga_dir}/status.sav"
+icinga_cmdfile="${icinga_dir}/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() {
+ for d in "${icinga_dir}" \
+ "${icinga_dir}/checkresults" \
+ "${icinga_logdir}" \
+ "${icinga_logdir}/archives"; do
+ if [ ! -d "${d}" ]; then
+ install -d -o "${icinga_user}" -g "${icinga_group}" "${d}"
+ fi
+ done
+
+ if [ ! -d "${icingadir}/rw" ]; then
+ install -d -o "${icinga_user}" -g "%%WWWGRP%%" "${icinga_dir}"/rw
+ fi
+
+ 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 "${icinga_dir}/icinga.tmp" "${icinga_cmdfile}"
+}
+
+start_cmd() {
+ ${command} ${command_args}
+}
+
+run_rc_command "$1"