Update version according to OSCI-883
[packages/precise/mcollective.git] / mcollective.init
index f599f4a8b5a6010ed0559bcf0de085ac7b82b59e..37e96abba75eb5c9b4b0b877a71d4a13731851cd 100755 (executable)
@@ -2,6 +2,7 @@
 #
 # mcollective   Application Server for STOMP based agents
 #
+# 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
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Start daemon at boot time
-# Description:       Enable service provided by mcollective.
+# Description:       Enable service provided by daemon.
 ### END INIT INFO
 
-# check permissions
+mcollectived="/usr/sbin/mcollectived"
 
-uid=`id -u`
-[ $uid -gt 0 ] && { echo "You need to be root to run file" ; exit 4 ; }
+# Lockfile
+if [ -d /var/lock/subsys ]; then
+    # RedHat/CentOS/etc who use subsys
+    lock="/var/lock/subsys/mcollective"
+else
+    # The rest of them
+    lock="/var/lock/mcollective"
+fi
 
 
 # PID directory
 pidfile="/var/run/mcollectived.pid"
 
-name="mcollective"
-mcollectived=/usr/sbin/mcollectived
-daemonopts="--pid=${pidfile}  --config=/etc/mcollective/server.cfg"
-
-
 # Source function library.
 . /lib/lsb/init-functions
 
@@ -38,34 +40,52 @@ daemonopts="--pid=${pidfile}  --config=/etc/mcollective/server.cfg"
 if ! [ -f $mcollectived ]
 then
     echo "mcollectived binary not found"
-    exit 5
+    exit 0
 fi
 
-# create pid file if it does not exist
-[ ! -f ${pidfile} ] && { touch ${pidfile} ; }
-
 # See how we were called.
 case "$1" in
     start)
-        echo "Starting daemon: " $name
-        # start the program
-        start-stop-daemon -S -p ${pidfile} --oknodo -q -a ${mcollectived} -- ${daemonopts}
-        [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
-        log_success_msg "mcollective started"
-        touch $lock
+        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}
+
+            rm -f ${lock}
+            sleep 2
+        fi
+
+        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
+            exit 1
+        fi
         ;;
     stop)
-        echo "Stopping daemon: " $name
-        start-stop-daemon -K -R 5 -s "TERM" --oknodo -q -p ${pidfile}
-        [ $? = 0 ] && { exit 0 ; } || { exit 1 ; }
-        log_success_msg "mcollective stopped"
+        echo -n "Shutting down mcollective: "
+
+        if [ -s ${pidfile} ]; then
+            kill `cat ${pidfile}` >/dev/null 2>&1
+        fi
+        rm -f ${pidfile}
+
+        log_success_msg
+        rm -f $lock
         ;;
     restart)
-        echo "Restarting daemon: " $name
         $0 stop
         sleep 2
         $0 start
-        [ $? = 0 ] && { echo "mcollective restarted" ; exit 0 ; }
         ;;
     condrestart)
         if [ -f $lock ]; then
@@ -76,10 +96,27 @@ case "$1" in
         fi
         ;;
     status)
-        status_of_proc -p ${pidfile} ${mcollectived} ${name} && exit 0 || exit $?
+        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 2
+        exit 1
         ;;
 esac
+exit 0