From: Dan Carley <[email protected]>

Use builtin RC functions for starting, stopping and checking status of daemon

- No longer restarts existing daemon when called with "start".
- Should hopefully alleviate issues of multiple daemons running.
- Some minor tidying.
- Backwards compatible with EL<5.
- Needs testing against LSB before changes are merged to "mcollective.init".
- Correct mixed whitespace. Standardised to 4 space indents.

Signed-off-by: R.I.Pienaar <[email protected]>
---
Local-branch: feature/master/7340
 mcollective.init    |  158 +++++++++++++++++++++++++------------------------
 mcollective.init-rh |  163 ++++++++++++++++++++++-----------------------------
 2 files changed, 151 insertions(+), 170 deletions(-)

diff --git a/mcollective.init b/mcollective.init
index f76b562..4187e58 100755
--- a/mcollective.init
+++ b/mcollective.init
@@ -1,12 +1,12 @@
 #!/bin/sh
 #
-# mcollective  Application Server for STOMP based agents
+# mcollective   Application Server for STOMP based agents
 #
-# chkconfig: 345 24 76
+# chkconfig:    345 24 76
 #
-# description: mcollective lets you build powerful Stomp compatible middleware 
clients in ruby without having to worry too
-#              much about all the setup and management of a Stomp connection, 
it also provides stats, logging and so forth
-#              as a bonus.
+# description:  mcollective lets you build powerful Stomp compatible 
middleware clients in ruby without having to worry too
+#               much about all the setup and management of a Stomp connection, 
it also provides stats, logging and so forth
+#               as a bonus.
 #
 ### BEGIN INIT INFO
 # Provides:          mcollective
@@ -25,11 +25,11 @@ mcollectived="/usr/sbin/mcollectived"
 
 # Lockfile
 if [ -d /var/lock/subsys ]; then
-  # RedHat/CentOS/etc who use subsys
-  lock="/var/lock/subsys/mcollective"
+    # RedHat/CentOS/etc who use subsys
+    lock="/var/lock/subsys/mcollective"
 else
-  # The rest of them
-  lock="/var/lock/mcollective"
+    # The rest of them
+    lock="/var/lock/mcollective"
 fi
 
 
@@ -40,86 +40,88 @@ pidfile="/var/run/mcollectived.pid"
 . /lib/lsb/init-functions
 
 # Check that binary exists
-if ! [ -f  $mcollectived ]
+if ! [ -f $mcollectived ]
 then
-  echo "mcollectived binary not found"
-  exit 0
+    echo "mcollectived binary not found"
+    exit 0
 fi
 
 # See how we were called.
 case "$1" in
-  start)
-       echo -n "Starting mcollective: "
+    start)
+        echo -n "Starting mcollective: "
 
-       if [ -f ${lock} ]; then
-           # we were not shut down correctly
-           if [ -s ${pidfile} ]; then
-               kill `cat ${pidfile}` >/dev/null 2>&1
-           fi
-           rm -f ${pidfile}
+        if [ -f ${lock} ]; then
+            # we were not shut down correctly
+            if [ -s ${pidfile} ]; then
+                kill `cat ${pidfile}` >/dev/null 2>&1
+            fi
+            rm -f ${pidfile}
 
-           rm -f ${lock}
-           sleep 2
-       fi
+            rm -f ${lock}
+            sleep 2
+        fi
 
-       rm -f ${pidfile}
+        rm -f ${pidfile}
 
-       ${mcollectived} --pid=${pidfile} --config="/etc/mcollective/server.cfg"
-       if [ $? = 0 ]; then
-           log_success_msg
-           touch $lock
-           exit 0
-       else
-           log_failure_msg
+        ${mcollectived} --pid=${pidfile} --config="/etc/mcollective/server.cfg"
+        if [ $? = 0 ]; then
+            success $"mcollectived"
+            touch $lock
+            echo
+            exit 0
+        else
+            failure
+            echo
             exit 1
-       fi
-       ;;
-  stop)
-       echo -n "Shutting down mcollective: "
+        fi
+        ;;
+    stop)
+        echo -n "Shutting down mcollective: "
 
-       if [ -s ${pidfile} ]; then
-         kill `cat ${pidfile}` >/dev/null 2>&1
-       fi
-       rm -f ${pidfile}
+        if [ -s ${pidfile} ]; then
+            kill `cat ${pidfile}` >/dev/null 2>&1
+        fi
+        rm -f ${pidfile}
 
-       log_success_msg
-       rm -f $lock
-       ;;
-  restart)
-       $0 stop
-       sleep 2
-       $0 start
-       ;;
-  condrestart)
-       if [ -f $lock ]; then
-           $0 stop
-           # avoid race
-           sleep 2
-           $0 start
-       fi
-       ;;
-  status)
-       if [ -f ${lock} ]; then
-           if [ -s ${pidfile} ]; then
-              if [ -e /proc/`cat ${pidfile}` ]; then
-                  echo "mcollectived (`cat ${pidfile}`) is running"
-                  exit 0
-               else
-                  echo "mcollectived (`cat ${pidfile}`) is NOT running"
-                  exit 1
-               fi
-           fi
-       else
-           echo "mcollectived: service not started"
-           exit 1
-       fi
-  ;;
-       force-reload)
-               echo "not implemented"
-       ;;
-  *)
-       echo "Usage: mcollectived {start|stop|restart|condrestart|status}"
-       exit 1
-       ;;
+        log_success_msg
+        rm -f $lock
+        ;;
+    restart)
+        $0 stop
+        sleep 2
+        $0 start
+        ;;
+    condrestart)
+        if [ -f $lock ]; then
+            $0 stop
+            # avoid race
+            sleep 2
+            $0 start
+        fi
+        ;;
+    status)
+        if [ -f ${lock} ]; then
+            if [ -s ${pidfile} ]; then
+                if [ -e /proc/`cat ${pidfile}` ]; then
+                    echo "mcollectived (`cat ${pidfile}`) is running"
+                    exit 0
+                else
+                    echo "mcollectived (`cat ${pidfile}`) is NOT running"
+                    exit 1
+                fi
+            fi
+        else
+            echo "mcollectived: service not started"
+            exit 1
+        fi
+        ;;
+    force-reload)
+        echo "not implemented"
+        ;;
+    *)
+        echo "Usage: mcollectived {start|stop|restart|condrestart|status}"
+        exit 1
+        ;;
 esac
 exit 0
diff --git a/mcollective.init-rh b/mcollective.init-rh
index 4be7aff..7a31dea 100755
--- a/mcollective.init-rh
+++ b/mcollective.init-rh
@@ -1,12 +1,12 @@
 #!/bin/sh
 #
-# mcollective  Application Server for STOMP based agents
+# mcollective   Application Server for STOMP based agents
 #
-# chkconfig: 345 24 76
+# chkconfig:    345 24 76
 #
-# description: mcollective lets you build powerful Stomp compatible middleware 
clients in ruby without having to worry too
-#              much about all the setup and management of a Stomp connection, 
it also provides stats, logging and so forth
-#              as a bonus.
+# description:  mcollective lets you build powerful Stomp compatible 
middleware clients in ruby without having to worry too
+#               much about all the setup and management of a Stomp connection, 
it also provides stats, logging and so forth
+#               as a bonus.
 #
 ### BEGIN INIT INFO
 # Provides:          mcollective
@@ -22,107 +22,86 @@ RUBYLIB=/usr/local/lib/site_ruby/1.8:$RUBYLIB
 export RUBYLIB
 
 mcollectived="/usr/sbin/mcollectived"
-
-# Lockfile
+pidfile="/var/run/mcollectived.pid"
 if [ -d /var/lock/subsys ]; then
-  # RedHat/CentOS/etc who use subsys
-  lock="/var/lock/subsys/mcollective"
+    # RedHat/CentOS/etc who use subsys
+    lockfile="/var/lock/subsys/mcollective"
 else
-  # The rest of them
-  lock="/var/lock/mcollective"
+    # The rest of them
+    lockfile="/var/lock/mcollective"
 fi
 
-
-# PID directory
-pidfile="/var/run/mcollectived.pid"
+# Check that binary exists
+if ! [ -f $mcollectived ]; then
+    echo "mcollectived binary not found"
+    exit 0
+fi
 
 # Source function library.
 . /etc/init.d/functions
 
-# Check that binary exists
-if ! [ -f  $mcollectived ]
-then
-  echo "mcollectived binary not found"
-  exit 0
+# Determine if we can use the -p option to daemon, killproc, and status.
+# RHEL < 5 can't.
+if status | grep -q -- '-p' 2>/dev/null; then
+    daemonopts="--pidfile $pidfile"
+    pidopts="-p $pidfile"
 fi
 
-# See how we were called.
-case "$1" in
-  start)
+start() {
        echo -n "Starting mcollective: "
+    daemon ${daemonopts} --pidfile=${pidfile} ${mcollectived} \
+        --pid=${pidfile} --config="/etc/mcollective/server.cfg"
+    RETVAL=$?
+    echo
+    [ $RETVAL -eq 0 ] && touch ${lockfile}
+    return $RETVAL
+}
 
-       if [ -f ${lock} ]; then
-           # we were not shut down correctly
-           if [ -s ${pidfile} ]; then
-               kill `cat ${pidfile}` >/dev/null 2>&1
-           fi
-           rm -f ${pidfile}
+stop() {
+    echo -n "Shutting down mcollective: "
+    killproc ${pidopts} -d 10 ${mcollectived}
+    RETVAL=$?
+    echo
+    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
+    return $RETVAL
+}
 
-           rm -f ${lock}
-           sleep 2
-       fi
+restart() {
+    stop
+    start
+}
 
-       rm -f ${pidfile}
+rh_status() {
+    status ${pidopts} ${mcollectived}
+    RETVAL=$?
+    return $RETVAL
+}
 
-       ${mcollectived} --pid=${pidfile} --config="/etc/mcollective/server.cfg"
-       if [ $? = 0 ]; then
-           success $"mcollectived"
-           touch $lock
-           echo
-           exit 0
-       else
-           failure
-            echo
-            exit 1
-       fi
-       ;;
-  stop)
-       echo -n "Shutting down mcollective: "
+rh_status_q() {
+    rh_status >/dev/null 2>&1
+}
 
-       if [ -s ${pidfile} ]; then
-         kill `cat ${pidfile}` >/dev/null 2>&1
-       fi
-       rm -f ${pidfile}
-
-       success $"mcollectived"
-       rm -f $lock
-       echo
-       ;;
-  restart)
-       $0 stop
-       sleep 2
-       $0 start
-       ;;
-  condrestart)
-       if [ -f $lock ]; then
-           $0 stop
-           # avoid race
-           sleep 2
-           $0 start
-       fi
-       ;;
-  status)
-       if [ -f ${lock} ]; then
-           if [ -s ${pidfile} ]; then
-              if [ -e /proc/`cat ${pidfile}` ]; then
-                  echo "mcollectived (`cat ${pidfile}`) is running"
-                  exit 0
-               else
-                  echo "mcollectived (`cat ${pidfile}`) is NOT running"
-                  exit 1
-               fi
-           fi
-       else
-           echo "mcollectived: service not started"
-           exit 1
-       fi
-  ;;
-       force-reload)
-               echo "not implemented"
-       ;;
-  *)
-       echo "Usage: mcollectived {start|stop|restart|condrestart|status}"
-       exit 1
-       ;;
+# See how we were called.
+case "$1" in
+    start)
+        start
+        ;;
+    stop)
+        stop
+        ;;
+    restart)
+        restart
+        ;;
+    condrestart)
+        rh_status_q || exit 0
+        restart
+        ;;
+    status)
+        rh_status
+        ;;
+    *)
+        echo "Usage: mcollectived {start|stop|restart|condrestart|status}"
+        RETVAL=2
+        ;;
 esac
-exit 0
+exit $RETVAL
-- 
1.7.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to