@@ -9,6 +9,51 @@ set -o pipefail
9
9
# Functions
10
10
# ###########################################################
11
11
12
+ # ##
13
+ # ## Create main supvervisord configuration file
14
+ # ##
15
+ supervisor_create_config () {
16
+ local path=" ${1} "
17
+
18
+ # Enable supervisorctl (default: disabled)
19
+ SVCTL_ENABLE=" ${SVCTL_ENABLE:- 0} "
20
+ if [ -z " ${SVCTL_USER:- } " ]; then
21
+ SVCTL_USER=" $( get_random_alphanum " 10" ) "
22
+ fi
23
+ if [ -z " ${SVCTL_PASS:- } " ]; then
24
+ SVCTL_PASS=" $( get_random_alphanum " 10" ) "
25
+ fi
26
+
27
+ {
28
+ # Use 'echo_supervisord_conf' to generate an example config
29
+ if [ " ${SVCTL_ENABLE} " = " 1" ]; then
30
+ echo " [rpcinterface:supervisor]"
31
+ echo " supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface"
32
+ echo
33
+ echo " [unix_http_server]"
34
+ echo " file = /tmp/supervisor.sock"
35
+ echo " chmod = 0700"
36
+ echo
37
+ echo " [supervisorctl]"
38
+ echo " serverurl = unix:///tmp/supervisor.sock"
39
+ echo " username = ${SVCTL_USER} ; should be same as in [*_http_server] if set"
40
+ echo " password = ${SVCTL_PASS} ; should be same as in [*_http_server] if set"
41
+ fi
42
+ echo " [supervisord]"
43
+ echo " user = root"
44
+ echo " nodaemon = true"
45
+ echo " loglevel = info"
46
+ echo " logfile = /var/log/supervisor/supervisord.log"
47
+ echo " pidfile = /var/run/supervisord.pid"
48
+ echo " childlogdir = /var/log/supervisor"
49
+ echo " strip_ansi = true" # Required to fix tail logs
50
+ echo
51
+ echo " [include]"
52
+ echo " files = /etc/supervisor/conf.d/*.conf /etc/supervisor/custom.d/*.conf"
53
+ } > " ${path} "
54
+ }
55
+
56
+
12
57
# ##
13
58
# ## Add service to supervisord
14
59
# ##
@@ -49,3 +94,26 @@ supervisor_add_service() {
49
94
echo " stderr_events_enabled = true" ;
50
95
} > " ${confd} /${name} .conf"
51
96
}
97
+
98
+
99
+ # ##
100
+ # ## Get Random alphanumeric string
101
+ # ##
102
+ get_random_alphanum () {
103
+ local len=" ${1:- 15} " # length defaults to 15
104
+ tr -dc A-Za-z0-9 < /dev/urandom | head -c " ${len} " | xargs || true
105
+ }
106
+
107
+
108
+ # ###########################################################
109
+ # Sanity Checks
110
+ # ###########################################################
111
+
112
+ if ! command -v tr > /dev/null 2>&1 ; then
113
+ echo " tr not found, but required."
114
+ exit 1
115
+ fi
116
+ if ! command -v xargs > /dev/null 2>&1 ; then
117
+ echo " xargs not found, but required."
118
+ exit 1
119
+ fi
0 commit comments