From d916e33f319551db9330a4150f2a0218a684f816 Mon Sep 17 00:00:00 2001
From: Mark Grondona <mgrondona@llnl.gov>
Date: Thu, 10 Apr 2003 22:43:14 +0000
Subject: [PATCH]  o Modified specfile to start slurmd even if it is running
 after an upgrade  o Added slurmstatus() function to slurm init.d script -- a
 modified version    of status() that tries to detect whether the "main"
 slurmd is running or    not.

---
 etc/init.d.slurm | 63 ++++++++++++++++++++++++++++++++++++++++++------
 slurm.spec.in    |  5 ++--
 2 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/etc/init.d.slurm b/etc/init.d.slurm
index e7ecce556e8..aa467da27f1 100644
--- a/etc/init.d.slurm
+++ b/etc/init.d.slurm
@@ -38,15 +38,16 @@ start() {
     daemon /usr/sbin/$1 $2
     RETVAL=$?
     echo
-    touch /var/lock/subsys/$prog 
+    touch /var/lock/subsys/slurm
     return $RETVAL
 }
 
-stop() { echo -n "stopping $1: "
+stop() { 
+    echo -n "stopping $1: "
     killproc $1 -TERM
     RETVAL=$?
     echo
-    rm -f /var/lock/subsys/$prog
+    rm -f /var/lock/subsys/slurm
     return $RETVAL
 }
 
@@ -57,6 +58,52 @@ startall() {
      done 
 }
 
+# status() with slight modifications to take into account
+# instantiations of job manager slurmd's, which should not be
+# counted as "running"
+#
+slurmstatus() {
+    local base=${1##*/}
+    local pid
+    local rpid
+    local pidfile
+
+    pidfile=`grep -i ${base}pid /etc/slurm/slurm.conf | grep -v '^ *#'`
+    if [ $? = 0 ]; then
+        pidfile=${pidfile##*=}
+    else
+        pidfile=/var/run/${base}.pid
+    fi
+
+    pid=`pidof -o $$ -o $$PPID -o %PPID -x $1 || \
+         pidof -o $$ -o $$PPID -o %PPID -x ${base}`
+
+    if [ -f $pidfile ]; then
+        read rpid < $pidfile
+        if [ "$rpid" != "" -a "$pid" != "" ]; then
+            for i in $pid ; do
+                if [ "$i" = "$rpid" ]; then 
+                    echo $"${base} (pid $pid) is running..."
+                    return 0
+                fi     
+            done
+        elif [ "$rpid" != "" -a "$pid" = "" ]; then
+            echo $"${base} dead but pid file exists"
+            return 1
+        fi 
+
+    fi
+
+    if [ "$base" = "slurmctld" -a "$pid" != "" ] ; then
+        echo $"${base} (pid $pid) is running..."
+        return 0
+    fi
+     
+    echo $"${base} is stopped"
+    
+    return 3
+}
+
 
 #
 # The pathname substitution in daemon command assumes prefix and
@@ -81,19 +128,19 @@ case "$1" in
         ;;
     status)
 	for prog in `scontrol show daemons`; do
-	   status $prog
+	   slurmstatus $prog
 	done
         ;;
     restart)
         $0 stop && $0 start
         ;;
     condrestart)
-        for prog in `scontrol show daemons`; do
-            if [ -f /var/lock/subsys/$prog ]; then
+        if [ -f /var/lock/subsys/slurm ]; then
+            for prog in `scontrol show daemons`; do
                  stop $prog
                  start $prog
-            fi
-        done
+            done
+        fi
         ;;
     reconfig)
 	for prog in `scontrol show daemons`; do
diff --git a/slurm.spec.in b/slurm.spec.in
index 6df2de3bec7..e65d34cb541 100644
--- a/slurm.spec.in
+++ b/slurm.spec.in
@@ -174,9 +174,10 @@ fi
 if [ -x /etc/rc.d/init.d/slurm ]; then
     [ -x /sbin/chkconfig ] && /sbin/chkconfig --del slurm
     [ -x /sbin/chkconfig ] && /sbin/chkconfig --add slurm
-    if ! /etc/rc.d/init.d/slurm status | grep -q running; then
+    if ! /etc/rc.d/init.d/slurm status | grep -q running \
+      || ! /etc/rc.d/init.d/slurm test | grep -q  slurmctld; then
         /etc/rc.d/init.d/slurm start
-    fi
+    fi 
 fi
 
 %preun
-- 
GitLab