File icinga_sysvinit_compat of Package icinga.9111

#! /bin/sh
# Copyright (c) 2014 SUSE Linux GmbH, Germany.
# Author: Lars Vogdt
# 
# /usr/sbin/rcicinga
#
# Systemd enhancements script for Icinga
#

. /etc/rc.status

ICINGA_BIN='/usr/sbin/icinga'
ICINGA_CFG='/etc/icinga/icinga.cfg'
ICINGA_CFG_ERR_LOG='/var/log/icinga/config.err'

# Read config and log errors in logfile
config_check () {
    case "$1" in
        verbose)
            $ICINGA_BIN -v "$ICINGA_CFG" >"$ICINGA_CFG_ERR_LOG" 2>&1
            if [ $? -eq 0 ]; then
                return 0
            else
                return 1
            fi
        ;;
        *)   
            $ICINGA_BIN -v "$ICINGA_CFG" >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                return 0
            else
                $ICINGA_BIN -v "$ICINGA_CFG" >"$ICINGA_CFG_ERR_LOG" 2>&1
                return 1
            fi
        ;;
    esac
}

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
test -x "$ICINGA_BIN" || { echo "$ICINGA_BIN not installed or not executable.";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Check for existence of needed config file
test -r "$ICINGA_CFG" || { echo "$ICINGA_CFG not existing or readable.";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

# Reset status of this service
rc_reset

case "$1" in
    check)
        echo -n "Starting configuration check "
        config_check
        if [ $? -eq 0 ]; then
            echo "- passed configuration check"
            test -f $ICINGA_CFG_ERR_LOG && rm $ICINGA_CFG_ERR_LOG
            rc_reset
        else
            echo "- detected Error in configuration files"
            echo "Please read $ICINGA_CFG_ERR_LOG"
            rc_failed
        fi
        rc_status -v
    ;;
    check_verbose)
        echo "Running verbose configuration check..."
        config_check verbose
        exitcode=$?
        cat "$ICINGA_CFG_ERR_LOG"
        rc_failed $exitcode
        rc_status -v
        rc_exit
    ;;
    *)
		/bin/systemctl $* icinga.service
        ;;
esac
rc_exit
openSUSE Build Service is sponsored by