]>
Commit | Line | Data |
---|---|---|
c8a620fd | 1 | #!@BASHPATH@ |
dac5df7d FDN |
2 | |
3 | # Authors: | |
4 | # Andrew Beekhof <abeekhof@redhat.com> | |
5 | # Fabio M. Di Nitto <fdinitto@redhat.com> | |
6 | # | |
7 | # License: Revised BSD | |
8 | ||
71c27024 | 9 | # chkconfig: - 20 80 |
dac5df7d FDN |
10 | # description: Corosync Cluster Engine |
11 | # processname: corosync | |
12 | # | |
13 | ### BEGIN INIT INFO | |
14 | # Provides: corosync | |
e1bbafca SD |
15 | # Required-Start: $network $syslog |
16 | # Required-Stop: $network $syslog | |
dac5df7d FDN |
17 | # Default-Start: |
18 | # Default-Stop: | |
19 | # Short-Description: Starts and stops Corosync Cluster Engine. | |
20 | # Description: Starts and stops Corosync Cluster Engine. | |
21 | ### END INIT INFO | |
22 | ||
23 | desc="Corosync Cluster Engine" | |
24 | prog="corosync" | |
4e77f108 | 25 | prog_pid_file="@LOCALSTATEDIR@/run/$prog.pid" |
dac5df7d FDN |
26 | |
27 | # set secure PATH | |
28 | PATH="/sbin:/bin:/usr/sbin:/usr/bin:@SBINDIR@" | |
29 | ||
30 | success() | |
31 | { | |
32 | echo -ne "[ OK ]\r" | |
33 | } | |
34 | ||
35 | failure() | |
36 | { | |
37 | echo -ne "[FAILED]\r" | |
38 | } | |
39 | ||
4e77f108 JF |
40 | # pid_var_run pid_file |
41 | # Echo pid from given pid_file. | |
42 | # Returns LSB exit code for the 'status' action. | |
43 | pid_var_run() | |
44 | { | |
45 | local pid_file="$1" | |
46 | local pid | |
47 | ||
48 | if [ -f "$pid_file" ]; then | |
49 | [ ! -r "$pid_file" ] && return 4 | |
50 | pid=$(cat "$pid_file") | |
51 | [ -z "$pid" ] && return 1 | |
52 | [ -n "${pid//[0-9]/}" ] && return 1 | |
53 | if kill -n 0 "$pid" 2>/dev/null;then | |
54 | echo "$pid" | |
55 | return 0 | |
56 | else | |
57 | return 1 | |
58 | fi | |
59 | fi | |
60 | ||
61 | return 3 | |
62 | } | |
63 | ||
64 | # status [-p pid_file] {program} | |
dac5df7d FDN |
65 | status() |
66 | { | |
4e77f108 JF |
67 | local pid_file |
68 | ||
69 | if [ "$1" = "-p" ]; then | |
70 | pid_file=$2 | |
71 | shift 2 | |
72 | fi | |
73 | ||
74 | pid=$(pid_var_run "$pid_file" 2>/dev/null) | |
7a6cc6b5 | 75 | res=$? |
4e77f108 JF |
76 | if [ $res -ne 0 -a -z "$pid_file" ]; then |
77 | pid=$(__pids_pidof "$1") | |
78 | [ -n "$pid" ] | |
79 | res=$? | |
80 | fi | |
81 | ||
7a6cc6b5 | 82 | if [ $res -ne 0 ]; then |
dac5df7d FDN |
83 | echo "$1 is stopped" |
84 | else | |
85 | echo "$1 (pid $pid) is running..." | |
86 | fi | |
7a6cc6b5 | 87 | return $res |
dac5df7d FDN |
88 | } |
89 | ||
d7208e88 FW |
90 | [ -f @INITCONFIGDIR@/$prog ] && . @INITCONFIGDIR@/$prog |
91 | ||
87a803ab FW |
92 | case '@INITCONFIGDIR@' in |
93 | */sysconfig) # rpm based distros | |
dac5df7d | 94 | [ -f @INITDDIR@/functions ] && . @INITDDIR@/functions |
87a803ab FW |
95 | [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/subsys/$prog";; |
96 | */default) # deb based distros | |
97 | [ -z "$LOCK_FILE" ] && LOCK_FILE="@LOCALSTATEDIR@/lock/$prog";; | |
98 | esac | |
dac5df7d | 99 | |
e725dd3e AB |
100 | # The version of __pids_pidof in /etc/init.d/functions calls pidof with -x |
101 | # This means it matches scripts, including this one. | |
102 | # Redefine it here so that status (from the same file) works. | |
103 | # Otherwise simultaneous calls to stop() will loop forever | |
104 | __pids_pidof() { | |
105 | pidof -c -o $$ -o $PPID -o %PPID "$1" || \ | |
106 | pidof -c -o $$ -o $PPID -o %PPID "${1##*/}" | |
107 | } | |
108 | ||
fbbb3f01 JF |
109 | cluster_disabled_at_boot() |
110 | { | |
111 | if grep -q nocluster /proc/cmdline && \ | |
112 | [ "$(tty)" = "/dev/console" ]; then | |
113 | echo -e "not configured to run at boot" | |
114 | failure | |
115 | return 1 | |
116 | fi | |
117 | return 0 | |
118 | } | |
119 | ||
d7e205d1 FDN |
120 | wait_for_ipc() |
121 | { | |
122 | try=0 | |
1f7e78ab JF |
123 | max_try=$((COROSYNC_INIT_TIMEOUT*2-1)) |
124 | [ "$max_try" -le "0" ] && max_try=120 | |
125 | ||
126 | while [ "$try" -le "$max_try" ]; do | |
d7e205d1 FDN |
127 | if corosync-cfgtool -s > /dev/null 2>&1; then |
128 | return 0 | |
129 | fi | |
130 | sleep 0.5 | |
131 | try=$((try + 1)) | |
132 | done | |
133 | ||
134 | return 1 | |
135 | } | |
136 | ||
dac5df7d FDN |
137 | start() |
138 | { | |
139 | echo -n "Starting $desc ($prog): " | |
140 | ||
fbbb3f01 JF |
141 | ! cluster_disabled_at_boot && return |
142 | ||
dac5df7d FDN |
143 | # most recent distributions use tmpfs for @LOCALSTATEDIR@/run |
144 | # to avoid to clean it up on every boot. | |
145 | # they also assume that init scripts will create | |
146 | # required subdirectories for proper operations | |
147 | mkdir -p @LOCALSTATEDIR@/run | |
148 | ||
4e77f108 | 149 | if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then |
dac5df7d FDN |
150 | success |
151 | else | |
1f7e78ab | 152 | $prog $COROSYNC_OPTIONS > /dev/null 2>&1 |
dac5df7d | 153 | |
b627844f | 154 | if [ "$?" != 0 ] || ! wait_for_ipc; then |
dac5df7d FDN |
155 | failure |
156 | rtrn=1 | |
b627844f JF |
157 | else |
158 | touch $LOCK_FILE | |
159 | success | |
dac5df7d FDN |
160 | fi |
161 | fi | |
162 | echo | |
163 | } | |
164 | ||
165 | stop() | |
166 | { | |
4e77f108 | 167 | ! status -p "$prog_pid_file" "$prog" > /dev/null 2>&1 && return |
60f6e2f2 | 168 | |
dac5df7d | 169 | echo -n "Signaling $desc ($prog) to terminate: " |
4e77f108 | 170 | kill -TERM "$(pid_var_run $prog_pid_file)" > /dev/null 2>&1 |
dac5df7d FDN |
171 | success |
172 | echo | |
173 | ||
174 | echo -n "Waiting for $prog services to unload:" | |
4e77f108 | 175 | while status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; do |
dac5df7d FDN |
176 | sleep 1 |
177 | echo -n "." | |
178 | done | |
179 | ||
180 | rm -f $LOCK_FILE | |
dac5df7d FDN |
181 | success |
182 | echo | |
183 | } | |
184 | ||
185 | restart() | |
186 | { | |
187 | stop | |
188 | start | |
189 | } | |
190 | ||
191 | rtrn=0 | |
192 | ||
193 | case "$1" in | |
194 | start) | |
195 | start | |
196 | ;; | |
197 | restart|reload|force-reload) | |
198 | restart | |
199 | ;; | |
200 | condrestart|try-restart) | |
4e77f108 | 201 | if status -p "$prog_pid_file" "$prog" > /dev/null 2>&1; then |
dac5df7d FDN |
202 | restart |
203 | fi | |
204 | ;; | |
205 | status) | |
4e77f108 | 206 | status -p "$prog_pid_file" "$prog" |
dac5df7d FDN |
207 | rtrn=$? |
208 | ;; | |
209 | stop) | |
210 | stop | |
211 | ;; | |
212 | *) | |
213 | echo "usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status}" | |
214 | rtrn=2 | |
215 | ;; | |
216 | esac | |
217 | ||
218 | exit $rtrn |