This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
supervisord
299 lines (265 loc) · 4.87 KB
/
supervisord
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/sh
# SUPERVISORD
# Maintainer: @sagikazarmark
# App Version: 3.0
#
#
# chkconfig: 2345 85 15
#
# description: Start/stop supervisor daemon and its configured subprocesses.
# processname: supervisord
# config: /etc/supervisord.conf
# pidfile: /var/run/supervisord.pid
#
#
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop supervisor
# Description: Start/stop supervisor daemon and its configured
# subprocesses.
### END INIT INFO
# LSB functions are available
if [ -f /lib/lsb/init-functions ]; then
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
. /lib/lsb/init-functions
else
# RedHat functions are available
if [ -f /etc/redhat-release ]; then
. /etc/rc.d/init.d/functions
status_of_proc()
{
status "$2"
}
else
COL="echo -n \\033[60G"
SUCCESS="\033[1;32m"
FAILURE="\033[1;31m"
WARNING="\033[1;33m"
NORMAL="echo -n \\033[0;39m"
echo_status()
{
color="${2:-\033[1;32m}"
$COL
echo -n "["
echo -n $color
echo -n " $1 "
$NORMAL
echo -n "]"
echo -n "\r"
return 0
}
echo_success() {
echo_status "OK"
}
echo_warning() {
echo_status "WARNING" "\033[1;33m"
}
echo_failure() {
echo_status "FAILED" "\033[1;31m"
}
status_of_proc()
{
log_daemon_msg "Status of $2"
if running; then
echo_status "RUNNING"
echo
return 0
else
echo_status "NOT RUNNING" "\033[1;31m"
echo
return 1
fi
}
pidofproc()
{
[ ! -f "$PIDFILE" ] && return 1
pid=`cat $PIDFILE`
(cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $1) || echo "0"
echo $pid
return 0
}
fi
# Alias functions to LSB
log_daemon_msg()
{
echo -n "$@ "
}
log_end_msg()
{
case "$1" in
0 )
echo_success
echo
;;
1 )
echo_failure
echo
;;
esac
}
log_warning_msg()
{
log_daemon_msg "$@"
echo_warning
echo
}
log_failure_msg()
{
log_daemon_msg "$@"
echo_failure
echo
}
log_success_msg()
{
log_daemon_msg "$@"
echo_success
echo
}
fi
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=supervisord
DESC="Supervisor daemon"
PIDFILE=/var/run/$NAME.pid
DODTIME=5
DAEMON=/usr/bin/$NAME
DAEMON_OPTS="-c /etc/$NAME.conf"
SUPERVISORCTL=/usr/bin/supervisorctl
test -x $DAEMON || exit 1
test -x $SUPERVISORCTL || exit 1
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Include supervisor defaults if available
if [ -f /etc/default/supervisor ] ; then
. /etc/default/supervisor
fi
running()
{
[ ! -f "$PIDFILE" ] && return 1
pid=`cat $PIDFILE`
proc=$(pidofproc $DAEMON)
[ "$pid" -eq "$proc" ] || return 1
return 0
}
do_start()
{
if ! running; then
log_daemon_msg "Starting $DESC" "$NAME"
$DAEMON --pidfile $PIDFILE $DAEMON_OPTS > /dev/null
test -f $PIDFILE || sleep 1
if running; then
log_end_msg 0
else
log_end_msg 1
fi
else
log_warning_msg "$DESC is currently running!"
fi
}
do_stop()
{
if running; then
log_daemon_msg "Stopping $DESC " "$NAME"
$SUPERVISORCTL $DAEMON_OPTS shutdown > /dev/null
test -f $PIDFILE || [ -n "$DODTIME" ] && sleep "$DODTIME"s
if running; then
log_end_msg 1
else
log_end_msg 0
fi
else
log_warning_msg "$DESC is currently not running!"
fi
}
do_force_stop()
{
if running; then
log_daemon_msg "Forcefully stopping $DESC" "$NAME"
$SUPERVISORCTL $DAEMON_OPTS shutdown > /dev/null
[ -n "$DODTIME" ] && sleep "$DODTIME"s
if running; then
kill -9 $pid
[ -n "$DODTIME" ] && sleep "$DODTIME"s
if running; then
log_failure_msg "Cannot kill $DESC (pid=$pid)!"
log_end_msg 1
else
rm -f $PIDFILE
log_end_msg 0
fi
else
rm -f $PIDFILE
log_end_msg 0
fi
else
log_warning_msg "$DESC is currently not running!"
fi
}
do_reload()
{
if running; then
log_daemon_msg "Reloading $DESC " "$NAME"
$SUPERVISORCTL $DAEMON_OPTS update > /dev/null
if running; then
log_end_msg 0
else
log_end_msg 1
fi
else
log_warning_msg "$DESC is currently not running!"
fi
}
do_restart()
{
if running; then
log_daemon_msg "Restarting $DESC" "$NAME"
$SUPERVISORCTL $DAEMON_OPTS reload > /dev/null
test -f $PIDFILE || sleep 1
if running; then
log_end_msg 0
else
log_end_msg 1
fi
else
log_warning_msg "$DESC is currently not running!"
fi
}
do_status()
{
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
}
case "$1" in
start )
do_start
;;
stop )
do_stop
;;
restart )
do_restart
;;
reload )
do_reload
;;
status )
do_status
;;
force-stop )
do_force_stop
;;
force-reload )
do_restart
;;
*)
log_daemon_msg "Usage: service $NAME {start|stop|restart|reload|status|force-stop|force-reload}" >&2
exit 1
;;
esac
exit 0