#!/bin/sh # # $FreeBSD$ # # PROVIDE: icinga2 # REQUIRE: LOGIN # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf to enable icinga2: # icinga2_enable (bool): Set to "NO" by default. # Set it to "YES" to enable icinga2. # icinga2_flags (str): Set to "" by default. # icinga2_configfile (str): Set to "%%PREFIX%%/etc/icinga2/icinga2.cfg" by default. # . /etc/rc.subr # Add /usr/local/bin to path, so that the notification scripts # can work (#!/usr/bin/env bash) export PATH=$PATH:%%LOCALBASE%%/bin name="icinga2" rcvar=icinga2_enable load_rc_config "${name}" : ${icinga2_enable:="NO"} : ${icinga2_configfile="%%PREFIX%%/etc/${name}/${name}.conf"} command="%%PREFIX%%/sbin/${name}" extra_commands="reload checkconfig configtest" icinga2_user="%%ICINGA2USER%%" icinga2_group="%%ICINGA2GROUP%%" icinga2_cachedir="/var/cache/${name}" icinga2_libdir="/var/lib/${name}" icinga2_logdir="%%ICINGA2LOGDIR%%" icinga2_rundir="/var/run/${name}" icinga2_spooldir="/var/spool/${name}" pidfile="${icinga2_rundir}/${name}.pid" icinga2_logfile="${icinga2_logdir}/${name}.log" icinga2_errorlogfile="${icinga2_logdir}/error.log" start_cmd="start_cmd" start_precmd="start_precmd" restart_precmd="icinga2_checkconfig" reload_precmd="reload_precmd" checkconfig_cmd="icinga2_checkconfig verbose" configtest_cmd="${checkconfig_cmd}" sig_reload=HUP required_files="${icinga2_configfile}" command_args="-d -e ${icinga2_errorlogfile} -u ${icinga2_user} -g ${icinga2_group} -c ${icinga2_configfile}" icinga2_checkconfig() { echo -n "Performing sanity check of icinga2 configuration: " if [ "$1" != "verbose" ]; then quietredir="2>&1 >/dev/null" fi ${command} -c ${icinga2_configfile} -C -u ${icinga2_user} -g ${icinga2_group} if [ $? -ne 0 ]; then echo "FAILED" return 1 else echo "OK" fi } reload_precmd() { if ! icinga2_checkconfig; then return 1 fi } start_precmd() { # Create necessary directories / change ownership for d in "${icinga2_logdir}" "${icinga2_logdir}/compat" \ "${icinga2_logdir}/compat/archives" "${icinga2_libdir}" \ "${icinga2_spooldir}" "${icinga2_spooldir}/tmp" \ "${icinga2_rundir}" "${icinga2_cachedir}"; do install -d -o ${icinga2_user} -g ${icinga2_group} "${d}" done install -d -o ${icinga2_user} -g %%WWWGRP%% "${icinga2_rundir}/cmd" chown -R ${icinga2_user}:${icinga2_user} "${icinga2_libdir}" chown -R ${icinga2_user}:${icinga2_user} "${icinga2_spooldir}" if ! icinga2_checkconfig; then return 1 fi if [ ! -f "${icinga2_logfile}" ]; then install -o "${icinga2_user}" -g "${icinga2_group}" -m 644 /dev/null "${icinga2_logfile}" fi } start_cmd() { ${command} ${command_args} } run_rc_command "$1"