diff --git a/script/lsb/booth-arbitrator b/script/lsb/booth-arbitrator index bad63bd..34f3a23 100755 --- a/script/lsb/booth-arbitrator +++ b/script/lsb/booth-arbitrator @@ -1,161 +1,154 @@ #!/bin/bash # # BOOTH daemon init script for LSB-compliant Linux distributions. # # booth-arbitrator BOOTH arbitrator daemon # # chkconfig: - 20 20 # processname: boothd # pidfile: /var/run/booth.pid # description: Cluster Ticket Registry ### BEGIN INIT INFO # Provides: booth # Required-Start: $network $syslog # Required-Stop: $network $syslog # Should-Start: # Should-Stop: # Default-Start: 3 5 # Default-Stop: 0 6 # Short-Description: start and stop BOOTH arbitrator daemon ### END INIT INFO prog="boothd" exec="/usr/sbin/$prog" -type="arbitrator" -lockfile="/var/run/booth.pid" + +CONF_DIR=/etc/booth + BOOTH_DAEMON_STARTED=0 BOOTH_DAEMON_STARTING=1 BOOTH_DAEMON_EXIST=2 BOOTH_DAEMON_NOT_RUNNING=3 BOOTH_ERROR_GENERIC=4 . /etc/rc.status check_status() { pidnum= - set -- `"$exec" "$type" -S "${cnf:+-c $cnf}"` - rc=$? + rc=$BOOTH_ERROR_GENERIC + eval `"$exec" status "${cnf:+-c$cnf}" ; echo rc=$?` case $rc in - $OCF_SUCCESS) - pidnum="$1" - daemonstate="$2" - act_type="$3" - config_name="$4" - act_site="$5" - - if test "$act_type" != "$OCF_RESKEY_type" then - case $daemonstate in - $BOOTH_DAEMON_STARTED) return $BOOTH_DAEMON_STARTED;; - $BOOTH_DAEMON_STARTING) return $BOOTH_DAEMON_STARTING;; - *) return $BOOTH_ERROR_GENERIC;; - esac - else - return $BOOTH_DAEMON_EXIST; - fi + 0) + case "$booth_state" in + started) return $BOOTH_DAEMON_STARTED;; + starting) return $BOOTH_DAEMON_STARTING;; + *) return $BOOTH_ERROR_GENERIC;; + esac ;; $OCF_NOT_RUNNING) return $BOOTH_DAEMON_NOT_RUNNING;; $OCF_ERR_GENERIC) return $BOOTH_ERROR_GENERIC;; *) return $BOOTH_ERROR_GENERIC;; esac } status() { - echo -n "BOOTH arbitrator daemon is " + echo -n "BOOTH daemon is " if check_status; then - echo "Running" + echo "running - PID $booth_pid for $booth_cfg_name, $booth_addr_string:$booth_port" return 0 else - echo "Stopped" + echo "stopped" return 7 fi } start() { [ -x $exec ] || exit 5 check_status; rc=$? case "$rc" in - $BOOTH_DAEMON_STARTED) - echo "BOOTH arbitrator daemon is Running" - return 0 - ;; - $BOOTH_DAEMON_STARTING) - echo "BOOTH arbitrator daemon is Running" + $BOOTH_DAEMON_STARTED|$BOOTH_DAEMON_STARTING|$BOOTH_DAEMON_EXIST) + echo "BOOTH daemon is running - PID $booth_pid for $booth_cfg_name, $booth_addr_string:$booth_port" return 0 ;; - $BOOTH_DAEMON_EXIST) - echo "BOOTH site daemon is Running" - return 1 - ;; - $BOOTH_DAEMON_NOT_RUNNING) - echo -n $"Starting BOOTH arbitrator daemon: " - startproc $exec $type "${cnf:+-c $cnf}" + $BOOTH_ERROR_GENERIC|$BOOTH_DAEMON_NOT_RUNNING) + echo -n $"Starting BOOTH arbitrator daemon: " + startproc $exec start "${cnf:+-c$cnf}" rc_status -v ;; + *) return $OCF_ERR_GENERIC;; esac } stop() { check_status; rc=$? case $rc in $BOOTH_DAEMON_STARTED);; $BOOTH_DAEMON_STARTING);; - $BOOTH_DAEMON_EXIST) - echo "BOOTH site daemon is running." - return 1 + $BOOTH_DAEMON_EXIST);; $BOOTH_DAEMON_NOT_RUNNING) echo "BOOTH arbitrator daemon is not running." return $OCF_SUCCESS ;; *) return $OCF_ERR_GENERIC;; esac echo -n $"Stopping BOOTH arbitrator daemon: " - kill -TERM $pidnum +# $exec stop "${cnf:+-c$cnf}" +# sleep 1 + if pkill -TERM -s $booth_pid boothd ; then + sleep 1 + pkill -KILL -s $booth_pid boothd + fi rc_status -v } wait_for_stop() { - while [ -e $lockfile ]; do +# while true ; do +# check_status ; rc=$? +# case $rc in +# $BOOTH_DAEMON_STARTED);; +# $BOOTH_DAEMON_STARTING);; +# *) return 0;; +# esac +# done + + while [ -e $booth_lockfile ]; do sleep .5 done } foreach() { - cd /etc/booth - set -- ${BOOTH_CONF_FILE:-*.conf} - for cnf in "$@" ; do + for cnf in ${BOOTH_CONF_FILE:-$CONF_DIR/*.conf} ; do if [ $# != 1 ] ; then echo "== For configuration file $cnf:" fi cnf_base=`basename $cnf` "$@" if [ $# != 1 ] ; then echo "== configuration file $cnf done" fi done } restart() { stop - wait_for_stop start } case "$1" in start|stop|restart) foreach $1 ;; reload|force-reload) foreach restart ;; condrestart|try-restart) - [ ! -f "$lockfile" ] || restart + [ ! -f "$booth_lockfile" ] || restart ;; status) foreach status ;; *) echo $"Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}" exit 2 esac