[icinga-checkins] icinga.org: icinga-core/fix/init-status-exit-4243: core: fix init script status exit codes on not running daemon and present pid file

git at icinga.org git at icinga.org
Sat Jun 29 18:29:15 CEST 2013


Module: icinga-core
Branch: fix/init-status-exit-4243
Commit: 45915d9042d04cb0a42aa9343e38f20f391b0c9e
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=45915d9042d04cb0a42aa9343e38f20f391b0c9e

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sat Jun 29 18:28:21 2013 +0200

core: fix init script status exit codes on not running daemon and present pid file

- exit 3 when daemon is not running (means no pid file)
- exit 1 when daemon is dead, but pid file there

fixes #4243

---

 Changelog      |    1 +
 daemon-init.in |   37 ++++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/Changelog b/Changelog
index 401f64a..d24573e 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ FIXES
 * core: multiple idomod modules: only first gets data from registered callback functions #4199 - MF
 * core: fix services with no host mappings are not accepted (Viranch Metha) #3961 - MF
 * core: remove event_profiling_enabled functionality causing core dumps #2244 - MF
+* core: fix init script status exit codes on not running daemon and present pid file #4243 - MF
 
 * classic ui: fixed Generated HTML code partly invalid #3608 - RB/Dakon
 
diff --git a/daemon-init.in b/daemon-init.in
index e15f7a1..ba35afc 100644
--- a/daemon-init.in
+++ b/daemon-init.in
@@ -55,6 +55,14 @@ fi
 
 
 ## helper functions ##
+check_pid_file_exists ()
+{
+        if test ! -f $IcingaRunFile; then
+                return 1;
+        fi
+
+        return 0
+}
 
 status_icinga ()
 {
@@ -69,17 +77,26 @@ status_icinga ()
 }
 
 
-printstatus_icinga()
+checkstatus_icinga()
 {
-
-	if status_icinga $1 $2; then
-		echo "icinga (pid $IcingaPID) is running..."
-	else
-		echo "icinga is not running"
-	fi
+        if check_pid_file_exists > /dev/null; then
+                pid_icinga
+                if status_icinga $1 $2; then
+                        echo "icinga (pid $IcingaPID) is running..."
+                        exit 0
+                else
+                        echo "icinga is not running. removing $IcingaRunFile"
+                        # pid file exists, but daemon is dead
+                        rm -f $IcingaRunFile
+                        exit 1
+                fi
+        else
+                # daemon not running
+                echo "icinga is not running"
+                exit 3
+        fi
 }
 
-
 killproc_icinga ()
 {
 	if kill -0  $IcingaPID  >/dev/null 2>&1; then
@@ -103,7 +120,6 @@ pid_icinga ()
 	IcingaPID=`head -n 1 $IcingaRunFile`
 }
 
-
 chk_config ()
 {
 	printf "Running configuration check..."
@@ -190,8 +206,7 @@ case "$1" in
 		;;
 
 	status)
-		pid_icinga
-		printstatus_icinga icinga
+		checkstatus_icinga icinga
 		;;
 
 	checkconfig)





More information about the icinga-checkins mailing list