]> granicus.if.org Git - icinga2/commitdiff
Less verbose start output using the initscript
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 12 Jun 2014 14:05:45 +0000 (16:05 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 12 Jun 2014 14:05:45 +0000 (16:05 +0200)
All output is dumped to startup.log and only shown in case of
'checkconfig' as parameter, but not during a reload/restart.

Furtermore some additional formatting to make it fit line by line.

fixes #5822

debian/icinga2-common.icinga2.init
etc/init.d/icinga2.cmake

index ef14d3b82c4f08fd72cca84ed09863a6f76104e2..07ebe12e846c9be6f4f7c1f9961d1ed1ed717112 100644 (file)
@@ -22,6 +22,7 @@ DAEMON_USER=nagios
 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
 
@@ -128,10 +129,10 @@ do_reload() {
 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
index 0e24daf44838c3fa0bbf41ad7495a7617a99a50f..007695e636ebf3806f0d442a1c0d0c11aed1e48d 100644 (file)
@@ -20,6 +20,7 @@ ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf
 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@
@@ -48,24 +49,34 @@ if [ -f /etc/default/icinga ]; then
         . /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"
@@ -75,6 +86,7 @@ start() {
 # 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
@@ -120,20 +132,26 @@ reload() {
 
 # 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
@@ -149,6 +167,8 @@ status() {
        fi
 }
 
+check_run
+
 ### main logic ###
 case "$1" in
   start)