forked from sio2project/sioworkers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
supervisor.sh
executable file
·98 lines (86 loc) · 2.15 KB
/
supervisor.sh
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
#!/bin/bash
help() {
cat << EOF
Usage: $0 [option] command
Helps managing supervisor with configuration in this script. The only way to
reload configuration is to restart supervisor with this script.
Options:
-h, --help display this help
Commands:
start starts supervisor
startfg starts supervisor in foreground
stop stops supervisor
restart restart supervisor
status shows status of daemons that supervisor run
shell run supervisorctl's shell
EOF
}
command=
while [ -n "$1" ]; do
case "$1" in
"-h"|"--help")
help
exit 0
;;
"start"|"startfg"|"stop"|"restart"|"status"|"shell")
command="$1"
;;
*)
echo "Unknown option: $1"
help
exit 1
;;
esac
shift
done
if [ -z "$command" ]; then
help
exit 1
fi
# Set CWD to directory with config.
cd "$(dirname "$BASH_SOURCE")/config"
if ! [ -e supervisord.conf ] || \
! [ -e supervisord-conf-vars.conf ]; then
echo "Please make sure that supervisord.conf and " \
"supervisord-conf-vars.conf exist in config/ directory!"
echo "You can copy example configs that resides in config/ directory."
exit 1
fi
# Activate venv:
if [ -d "../../venv" ]
then
source ../../venv/bin/activate
fi
# Set all config variables.
source supervisord-conf-vars.conf
# Set extra flags, currently there is a need only for --can-run-cpu-exec flag.
if [ "$WORKER_ALLOW_RUN_CPU_EXEC" == "true" ]; then
export WORKER_EXTRA_FLAGS="--can-run-cpu-exec"
else
export WORKER_EXTRA_FLAGS=""
fi
# Create necessary directories.
mkdir -pv "${WORKER_HOME}"/{logs,pidfiles}
# And run supervisor.*
case "$command" in
"start")
exec supervisord
;;
"startfg")
exec supervisord -n
;;
"stop")
exec supervisorctl shutdown
;;
"restart")
supervisorctl shutdown
exec supervisord
;;
"status")
exec supervisorctl status
;;
"shell")
echo "Caution: In order to reload config, run \`$0 restart\`"
exec supervisorctl
;;
esac