From: Dmitry Burmistrov Date: Thu, 21 Nov 2013 12:31:48 +0000 (+0400) Subject: Update mcollective.init script according to OSCI-921 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=00d2b01f539a18a8c8fcf7abdd77ce0c24074959;p=packages%2Fprecise%2Fmcollective.git Update mcollective.init script according to OSCI-921 --- diff --git a/debian/mcollective.init b/debian/mcollective.init index c4e822c..6fb229b 100755 --- a/debian/mcollective.init +++ b/debian/mcollective.init @@ -24,11 +24,11 @@ uid=`id -u` # PID directory -pidfile="/var/run/mcollectived.pid" +pidfile="/var/run/mcollective.pid" name="mcollective" mcollectived=/usr/sbin/mcollectived -daemonopts="--pid=${pidfile} --config=/etc/mcollective/server.cfg" +daemonopts="--config=/etc/mcollective/server.cfg" # Source function library. @@ -41,22 +41,30 @@ then exit 5 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 ; } + if [ -f $pidfile ]; then + if [ -f "$(cat /proc/$(cat $pidfile)/exe > /dev/null)" ] ; then + echo MCollective appears to be running + exit 1 + else + /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts + [ $? = 0 ] && { exit 0 ; } || { exit 1 ; } + fi + else + /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts + fi log_success_msg "mcollective started" - touch $lock ;; stop) echo "Stopping daemon: " $name - start-stop-daemon -K -R 5 -s "TERM" --oknodo -q -p ${pidfile} + /sbin/start-stop-daemon --stop -q --pidfile $pidfile + if [ -f $pidfile ]; then + rm -f $pidfile + fi [ $? = 0 ] && { exit 0 ; } || { exit 1 ; } log_success_msg "mcollective stopped" ;; @@ -67,17 +75,6 @@ case "$1" in $0 start [ $? = 0 ] && { echo "mcollective restarted" ; exit 0 ; } ;; - condrestart) - if [ -f $lock ]; then - $0 stop - # avoid race - sleep 2 - $0 start - fi - ;; - force-reload) - echo "not implemented" - ;; status) status_of_proc -p ${pidfile} ${mcollectived} ${name} && exit 0 || exit $? ;; diff --git a/mcollective.init b/mcollective.init index 37e96ab..6fb229b 100755 --- a/mcollective.init +++ b/mcollective.init @@ -2,7 +2,6 @@ # # 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 @@ -15,23 +14,22 @@ # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time -# Description: Enable service provided by daemon. +# Description: Enable service provided by mcollective. ### END INIT INFO -mcollectived="/usr/sbin/mcollectived" +# check permissions -# 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 +uid=`id -u` +[ $uid -gt 0 ] && { echo "You need to be root to run file" ; exit 4 ; } # PID directory -pidfile="/var/run/mcollectived.pid" +pidfile="/var/run/mcollective.pid" + +name="mcollective" +mcollectived=/usr/sbin/mcollectived +daemonopts="--config=/etc/mcollective/server.cfg" + # Source function library. . /lib/lsb/init-functions @@ -40,83 +38,48 @@ pidfile="/var/run/mcollectived.pid" if ! [ -f $mcollectived ] then echo "mcollectived binary not found" - exit 0 + exit 5 fi # See how we were called. case "$1" in 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} - - 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 + echo "Starting daemon: " $name + # start the program + if [ -f $pidfile ]; then + if [ -f "$(cat /proc/$(cat $pidfile)/exe > /dev/null)" ] ; then + echo MCollective appears to be running + exit 1 + else + /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts + [ $? = 0 ] && { exit 0 ; } || { exit 1 ; } + fi + else + /sbin/start-stop-daemon --start -b --quiet --oknodo -m --pidfile $pidfile --exec $mcollectived -- $daemonopts + fi + log_success_msg "mcollective started" ;; stop) - 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 + echo "Stopping daemon: " $name + /sbin/start-stop-daemon --stop -q --pidfile $pidfile + if [ -f $pidfile ]; then + rm -f $pidfile + fi + [ $? = 0 ] && { exit 0 ; } || { exit 1 ; } + log_success_msg "mcollective stopped" ;; restart) + echo "Restarting daemon: " $name $0 stop sleep 2 $0 start - ;; - condrestart) - if [ -f $lock ]; then - $0 stop - # avoid race - sleep 2 - $0 start - fi + [ $? = 0 ] && { echo "mcollective restarted" ; exit 0 ; } ;; 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" + status_of_proc -p ${pidfile} ${mcollectived} ${name} && exit 0 || exit $? ;; *) echo "Usage: mcollectived {start|stop|restart|condrestart|status}" - exit 1 + exit 2 ;; esac -exit 0