-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
15-supervisord.sh
executable file
·108 lines (94 loc) · 3.34 KB
/
15-supervisord.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
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
###
### This file holds functions to conigure supervisord
###
# -------------------------------------------------------------------------------------------------
# ACTION FUNCTIONS
# -------------------------------------------------------------------------------------------------
###
### Create supervisord.conf
###
supervisord_create() {
local httpd_command="${1}"
local watcherd_command="${2}"
local config="${3}"
if [ -d "$( basename "${config}" )" ]; then
mkdir -p "$( basename "${config}" )"
fi
# Enable supervisorctl (default: disabled)
SVCTL_ENABLE="${SVCTL_ENABLE:-0}"
SVCTL_LISTEN_ADDR="0.0.0.0"
SVCTL_LISTEN_PORT=9001
if [ -z "${SVCTL_USER:-}" ]; then
SVCTL_USER="$( get_random_alphanum "10" )"
fi
if [ -z "${SVCTL_PASS:-}" ]; then
SVCTL_PASS="$( get_random_alphanum "10" )"
fi
if [ "${SVCTL_LISTEN_ADDR}" = "0.0.0.0" ] || [ "${SVCTL_LISTEN_ADDR}" = "*" ]; then
SVCTL_CONNECT_ADDR="127.0.0.1"
fi
# Allow tailing remote logs from supervisord via supervisorctl
SVCTL_REMOTE_LOGS_ENABLE="${SVCTL_REMOTE_LOGS_ENABLE:-0}"
# This allows for 'supvervisorctl restart watcherd
{
# Use 'echo_supervisord_conf' to generate an example config
if [ "${SVCTL_ENABLE}" = "1" ]; then
echo "[rpcinterface:supervisor]"
echo "supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface"
echo
echo "[inet_http_server] ; inet (TCP) server disabled by default"
echo "port=${SVCTL_LISTEN_ADDR}:${SVCTL_LISTEN_PORT} ; ip_address:port specifier, *:port for all iface"
echo "username=${SVCTL_USER} ; default is no username (open server)"
echo "password=${SVCTL_PASS} ; default is no password (open server)"
echo
echo "[supervisorctl]"
echo ";serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket"
echo "serverurl=http://${SVCTL_CONNECT_ADDR}:${SVCTL_LISTEN_PORT} ; http:// url to specify an inet socket"
echo "username=${SVCTL_USER} ; should be same as in [*_http_server] if set"
echo "password=${SVCTL_PASS} ; should be same as in [*_http_server] if set"
echo ";prompt=mysupervisor ; cmd line prompt (default 'supervisor')"
echo ";history_file=~/.sc_history ; use readline history if available"
echo
fi
echo "[supervisord]"
echo "user=root"
echo "nodaemon=true"
echo "loglevel=warn"
echo "strip_ansi=true" # Required to fix tail logs for watcherd
echo
echo "[program:httpd]"
echo "command=${httpd_command}"
echo "priority=1"
echo "autostart=true"
echo "startretries=100"
echo "startsecs=1"
echo "autorestart=true"
echo "stdout_logfile=/dev/stdout"
echo "stderr_logfile=/dev/stderr"
echo "stdout_logfile_maxbytes=0"
echo "stderr_logfile_maxbytes=0"
echo "stdout_events_enabled=true"
echo "stderr_events_enabled=true"
echo
echo "[program:watcherd]"
echo "command=${watcherd_command}"
echo "priority=999"
echo "autostart=true"
echo "autorestart=true"
if [ "${SVCTL_REMOTE_LOGS_ENABLE}" = "1" ]; then
echo "stdout_logfile=/var/log/supervisord-watcherd.log"
echo "stderr_logfile=/var/log/supervisord-watcherd.err"
else
echo "stdout_logfile=/dev/stdout"
echo "stderr_logfile=/dev/stderr"
fi
echo "stdout_logfile_maxbytes=0"
echo "stderr_logfile_maxbytes=0"
echo "stdout_events_enabled=true"
echo "stderr_events_enabled=true"
} > "${config}"
}