Debian Codegraph @

script/lsb/booth-arbitrator

raw
1 #!/bin/bash
2 #
3 # BOOTH daemon init script for SUSE Linux based distributions
4 # (almost LSB-compliant, except for s/startproc/start_daemon/ etc.)
5 #
6 # booth-arbitrator BOOTH arbitrator daemon
7 #
8 # chkconfig: - 20 20
9 # processname: boothd
10 # pidfile: /var/run/booth.pid
11 # description: Cluster Ticket Registry
12 ### BEGIN INIT INFO
13 # Provides: booth
14 # Required-Start: $network $syslog
15 # Required-Stop: $network $syslog
16 # Should-Start:
17 # Should-Stop:
18 # Default-Start: 3 5
19 # Default-Stop: 0 6
20 # Short-Description: start and stop BOOTH arbitrator daemon
21 ### END INIT INFO
22
23 prog="boothd"
24 exec="/usr/sbin/$prog"
25
26 CONF_DIR=/etc/booth
27
28
29 BOOTH_DAEMON_STARTED=0
30 BOOTH_DAEMON_STARTING=1
31 BOOTH_DAEMON_EXIST=2
32 BOOTH_DAEMON_NOT_RUNNING=3
33 BOOTH_ERROR_GENERIC=4
34 OCF_ERR_GENERIC=1
35 OCF_NOT_RUNNING=7
36
37 . /etc/rc.status
38
39 check_status() {
40 local rc
41
42 rc=$BOOTH_ERROR_GENERIC
43 eval `"$exec" status "${cnf:+-c$cnf}" ; echo rc=$?`
44 case $rc in
45 0)
46 # shellcheck disable=SC2154
47 case "$booth_state" in
48 started) return $BOOTH_DAEMON_STARTED;;
49 starting) return $BOOTH_DAEMON_STARTING;;
50 *) return $BOOTH_ERROR_GENERIC;;
51 esac
52 ;;
53 $OCF_NOT_RUNNING) return $BOOTH_DAEMON_NOT_RUNNING;;
54 $OCF_ERR_GENERIC) return $BOOTH_ERROR_GENERIC;;
55 *) return $BOOTH_ERROR_GENERIC;;
56 esac
57 }
58
59 status() {
60 printf "BOOTH daemon is "
61 if check_status; then
62 # shellcheck disable=SC2154
63 echo "running - PID $booth_lockpid for $booth_cfg_name, $booth_addr_string:$booth_port"
64 return 0
65 else
66 echo "stopped"
67 return 3
68 fi
69 }
70
71 start() {
72 local rc
73
74 [ -x $exec ] || exit 5
75 check_status; rc=$?
76 case "$rc" in
77 $BOOTH_DAEMON_STARTED|$BOOTH_DAEMON_STARTING|$BOOTH_DAEMON_EXIST)
78 echo "BOOTH daemon is running - PID $booth_lockpid for $booth_cfg_name, $booth_addr_string:$booth_port"
79 return 0
80 ;;
81 $BOOTH_ERROR_GENERIC|$BOOTH_DAEMON_NOT_RUNNING)
82 printf "Starting BOOTH arbitrator daemon: "
83 startproc $exec start "${cnf:+-c$cnf}"
84 rc_status -v
85 ;;
86 *) return 1;;
87 esac
88 }
89
90 stop() {
91 local rc wait_time
92
93 wait_time=5
94 check_status; rc=$?
95 case $rc in
96 $BOOTH_DAEMON_STARTED|$BOOTH_DAEMON_STARTING|$BOOTH_DAEMON_EXIST)
97 ;;
98 $BOOTH_DAEMON_NOT_RUNNING)
99 echo "BOOTH arbitrator daemon is not running."
100 return 0
101 ;;
102 *) return 1;;
103 esac
104
105 printf "Stopping BOOTH arbitrator daemon: "
106 # $exec stop "${cnf:+-c$cnf}"
107 # sleep 1
108 pkill -TERM -s $booth_lockpid boothd
109 sleep 0.1
110 check_status; rc=$?
111 while [ $rc -ne $BOOTH_DAEMON_NOT_RUNNING -a $wait_time -gt 0 ]
112 do
113 wait_time=$((wait_time-1))
114 sleep 1
115 check_status; rc=$?
116 done
117 if [ $rc -ne $BOOTH_DAEMON_NOT_RUNNING ]; then
118 pkill -KILL -s $booth_lockpid boothd
119 sleep 1
120 check_status; rc=$?
121 fi
122 test $rc -eq $BOOTH_DAEMON_NOT_RUNNING
123 rc_status -v
124 }
125
126 foreach() {
127 local cnf
128 local rc=0
129
130 for cnf in ${BOOTH_CONF_FILE:-$CONF_DIR/*.conf} ; do
131 "$@"
132 rc=$((rc|$?))
133 done
134 return $rc
135 }
136
137 restart() {
138 stop
139 start
140 }
141
142 condrestart() {
143 local rc
144
145 check_status; rc=$?
146
147 case "$rc" in
148 $BOOTH_DAEMON_STARTED|$BOOTH_DAEMON_STARTING|$BOOTH_DAEMON_EXIST)
149 # shellcheck disable=SC2154
150 [ ! -f "$booth_lockfile" ] || restart
151 ;;
152 esac
153 }
154
155 case "$1" in
156 start|stop|restart|condrestart|status)
157 foreach $1
158 ;;
159 reload|force-reload)
160 foreach restart
161 ;;
162 try-restart)
163 foreach condrestart
164 ;;
165 *)
166 echo "Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}"
167 exit 2
168 ;;
169 esac