[omd-commits] OMD Git: omd: Init-Scripts now work with newer upstart versions

git version control git at mathias-kettner.de
Tue Oct 22 10:15:30 CEST 2013


Module:   omd
Branch:   master
Commit:   a253694299f9010711dbbb0a602142a34572af67
URL:      http://omdistro.org/projects/omd/repository/revisions/a253694299f9010711dbbb0a602142a34572af67

Author:   Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Oct 22 10:11:08 2013 +0200
Commiter: Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Oct 22 10:11:08 2013 +0200

Init-Scripts now work with newer upstart versions

Init scripts can now deal with upstart user sessions, where the
PPID is not 1 anymore, instead of it the PPID is the user
session init process (init --user). Until the user session ends,
then the PPID is 1. This was first seen on ubuntu 13.10.

---

 Changelog                                  |    3 +++
 packages/apache-omd/skel/etc/init.d/apache |    6 +++---
 packages/nagios/skel/etc/init.d/nagios     |    9 ++++++++-
 packages/pnp4nagios/skel/etc/init.d/npcd   |    7 +++----
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Changelog b/Changelog
index 774320d..fd0ab8c 100644
--- a/Changelog
+++ b/Changelog
@@ -18,6 +18,9 @@ This file documents the revision history for the Open Monitoring Distribution
           - Fix bug on Debian/Ubuntu where start/stop script started/stopped
              sites multiple times
           - cleanup checkresults dir of Nagios when (re-)starting Nagios
+          - Init scripts can now deal with upstart user sessions, where the
+            PPID is not 1 anymore, instead of it the PPID is the user session
+            init process (init --user). This was first seen on ubuntu 13.10.
 
 1.00     Jun 17 2013
           - Nagios: Update to 3.5.0
diff --git a/packages/apache-omd/skel/etc/init.d/apache b/packages/apache-omd/skel/etc/init.d/apache
index 17b4099..d2e1579 100644
--- a/packages/apache-omd/skel/etc/init.d/apache
+++ b/packages/apache-omd/skel/etc/init.d/apache
@@ -32,9 +32,9 @@ pidof_apache() {
     fi
   else
     # It might happen that there is no pidfile but a process is running
-    # As fallback check the process table for apache with PPID=1 and
+    # As fallback check the process table for the oldest apache process
     # running as this user
-    PID=$(pgrep -u $OMD_SITE -P 1 -f $APACHE_BIN)
+    PID=$(pgrep -u $OMD_SITE -o -f $APACHE_BIN)
     if [ -n "$PID" ]; then
         echo $PID
         return 0
@@ -84,7 +84,7 @@ apache_wait_start() {
   # (nearly) reproducible problems with apache at boot-time. (alloc_listener: failed to set up sockaddr for 127.0.0.1)
   # With this ping the problem disappears.
   test -f /etc/debian_version && test $(cut -f1 -d"." /proc/uptime) -lt 300 && ping -nqc 10 $CONFIG_APACHE_TCP_ADDR >/dev/null 2>&1
-  $APACHE_BIN -f "$CONFIG_FILE"
+  setsid $APACHE_BIN -f "$CONFIG_FILE"
   
   i=0
   while ! pidof_apache >/dev/null 2>&1;  do
diff --git a/packages/nagios/skel/etc/init.d/nagios b/packages/nagios/skel/etc/init.d/nagios
index 8646045..a911307 100755
--- a/packages/nagios/skel/etc/init.d/nagios
+++ b/packages/nagios/skel/etc/init.d/nagios
@@ -76,11 +76,18 @@ OPTIONS="-ud"
 #
 # --ppid 1 in ps seem not to filter by direct ppid but by the whole
 # parent process tree. So filter by hand again.
+#
+# Removed the filter "-P 1" (filters for ppid=1 processes) as on some
+# distros, like Ubuntu 13.10 and newer, the processes will not be childs
+# of PID 1, instead the process is child of an "upstart user session",
+# which is visible via ps as "init --user". This will be the PPID until
+# the user session ends, then the process will be moved to PPID=1.
+# Strange one, but we try to simply ignore that...  "-o" should make it.
 # 
 # It returns 1 when no process can be found and echos the PID while
 # returning 0 when a process can be found.
 pidof_nagios() {
-    pgrep -u $OMD_SITE -o -P 1 -fx "$BIN $OPTIONS $CFG_FILE" 2>/dev/null
+    pgrep -u $OMD_SITE -o -fx "$BIN $OPTIONS $CFG_FILE" 2>/dev/null
 }
 
 
diff --git a/packages/pnp4nagios/skel/etc/init.d/npcd b/packages/pnp4nagios/skel/etc/init.d/npcd
index a41d5be..1cf01d8 100644
--- a/packages/pnp4nagios/skel/etc/init.d/npcd
+++ b/packages/pnp4nagios/skel/etc/init.d/npcd
@@ -75,10 +75,9 @@ pid_npcd (){
     fi
 
     # It might happen that there is no pidfile or a stale pidfile but
-    # a process is running
-    # As fallback check the process table for a process with PPID=1 and
-    # running as this user
-    PID=$(pgrep -u $OMD_SITE -P 1 -f $NpcdBin)
+    # a process is running. As fallback check the process table for the
+    # oldest process executed by the site user
+    PID=$(pgrep -u $OMD_SITE -o -f $NpcdBin)
     if [ -n "$PID" ]; then
         NpcdPID=$PID
         return 0



More information about the omd-commits mailing list