[icinga-checkins] icinga.org: icinga2/next: Less verbose start output using the initscript

git at icinga.org git at icinga.org
Thu Jun 12 16:07:13 CEST 2014


Module: icinga2
Branch: next
Commit: 6bebdddf98021b598ce753678b30933b5e2c269b
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=6bebdddf98021b598ce753678b30933b5e2c269b

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Jun 12 16:05:45 2014 +0200

Less verbose start output using the initscript

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 |    7 +++---
 etc/init.d/icinga2.cmake           |   44 ++++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/debian/icinga2-common.icinga2.init b/debian/icinga2-common.icinga2.init
index ef14d3b..07ebe12 100644
--- a/debian/icinga2-common.icinga2.init
+++ b/debian/icinga2-common.icinga2.init
@@ -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
diff --git a/etc/init.d/icinga2.cmake b/etc/init.d/icinga2.cmake
index 0e24daf..007695e 100644
--- a/etc/init.d/icinga2.cmake
+++ b/etc/init.d/icinga2.cmake
@@ -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)



More information about the icinga-checkins mailing list