DAEMON_GROUP=nagios
DAEMON_CMDGROUP=www-data
DAEMON_ARGS="-e /var/log/icinga2/icinga2.err"
+STARTUP_LOG="/var/log/icinga2/startup.log"
PIDFILE=/var/run/icinga2/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
do_check_config () {
DOEXITONOK="$1"
log_begin_msg "checking Icinga2 configuration"
- if ! check_config >/dev/null 2>&1; then
+ if ! check_config >$STARTUP_LOG 2>&1; then
echo
- check_config
- log_failure_msg "checking Icinga2 configuration"
+ [ -n "$DOEXITONOK" ] && cat $STARTUP_LOG
+ log_failure_msg "checking Icinga2 configuration. Check '$STARTUP_LOG' for details."
exit 1
else
log_end_msg 0
ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@
ICINGA2_PID_FILE=$ICINGA2_STATE_DIR/run/icinga2/icinga2.pid
ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log
+ICINGA2_STARTUP_LOG=$ICINGA2_STATE_DIR/log/icinga2/startup.log
ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log
ICINGA2_USER=@ICINGA2_USER@
ICINGA2_GROUP=@ICINGA2_GROUP@
. /etc/default/icinga
fi
-# Start Icinga 2
-start() {
+check_run() {
mkdir -p $(dirname -- $ICINGA2_PID_FILE)
chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE)
- chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
+ if [ -f $ICINGA2_PID_FILE ]; then
+ chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
+ fi
mkdir -p $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG)
chmod 750 $(dirname -- $ICINGA2_ERROR_LOG)
- chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG $ICINGA2_LOG
+ if [ -f $ICINGA2_ERROR_LOG ]; then
+ chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG
+ fi
+ if [ -f $ICINGA2_LOG ]; then
+ chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_LOG
+ fi
mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
+}
+
+# Start Icinga 2
+start() {
+ printf "Starting Icinga 2: "
- echo "Starting Icinga 2: "
- if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP; then
- echo "Error starting Icinga."
+ if ! $DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then
+ echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
exit 1
else
echo "Done"
# Restart Icinga 2
stop() {
printf "Stopping Icinga 2: "
+
if [ ! -e $ICINGA2_PID_FILE ]; then
echo "The PID file '$ICINGA2_PID_FILE' does not exist."
if [ "x$1" = "xnofail" ]; then
# Check the Icinga 2 configuration
checkconfig() {
- printf "Checking configuration:"
+ printf "Checking configuration: "
- echo "Validating the configuration file:"
- if ! $DAEMON -c $ICINGA2_CONFIG_FILE -C -u $ICINGA2_USER -g $ICINGA2_GROUP; then
+ if ! $DAEMON -c $ICINGA2_CONFIG_FILE -C -u $ICINGA2_USER -g $ICINGA2_GROUP > $ICINGA2_STARTUP_LOG 2>&1; then
if [ "x$1" = "x" ]; then
- echo "Icinga 2 detected configuration errors."
+ cat $ICINGA2_STARTUP_LOG
+ echo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
exit 1
else
- echo "Not "$1"ing Icinga 2 due to configuration errors."
+ echo "Not "$1"ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
if [ "x$2" = "xfail" ]; then
exit 1
fi
fi
fi
+
+ echo "Done"
+ # no arguments requires full output
+ if [ "x$1" = "x" ]; then
+ cat $ICINGA2_STARTUP_LOG
+ fi
}
# Print status for Icinga 2
fi
}
+check_run
+
### main logic ###
case "$1" in
start)