-
Notifications
You must be signed in to change notification settings - Fork 276
/
bootstrap
executable file
·161 lines (141 loc) · 4.31 KB
/
bootstrap
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
#!/bin/bash
# Bootstraps supervisor config
# Include defaults
. /usr/local/etc/valheim/defaults
. /usr/local/etc/valheim/common
main() {
apply_permissions
configure_timezone
setup_syslog
setup_supervisor_http_server
setup_status_http_server
pre_supervisor_hook
exec /usr/local/bin/supervisord -c /usr/local/etc/supervisord.conf
}
# Apply user id and group id
apply_permissions() {
info "Setting uid:gid of valheim to $PUID:$PGID"
groupmod -g "${PGID}" -o valheim
#usermod -u "${PUID}" -o -g valheim valheim
sed -i -E "s/^(valheim:x):[0-9]+:[0-9]+:(.*)/\\1:$PUID:$PGID:\\2/" /etc/passwd
touch "$SERVER_STATUS_FILE"
chown -R valheim:valheim \
/config \
/opt/valheim \
/opt/steamcmd \
/home/valheim \
/var/run/valheim \
"$SERVER_STATUS_FILE"
chgrp valheim /usr/local/etc/supervisord.conf
}
# Configure timezone
configure_timezone() {
export TZ
if [ ! -f "/usr/share/zoneinfo/$TZ" ]; then
warn "Unknown timezone $TZ - defaulting to Etc/UTC"
TZ="Etc/UTC"
fi
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime
echo "$TZ" > /etc/timezone
info "Setting timezone $TZ"
}
# Configure syslog
setup_syslog() {
local SYSLOG_ARGS
local log_msg
SYSLOG_ARGS="-S -t -O -"
log_target_msg="stdout"
if [ -n "$SYSLOG_REMOTE_HOST" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -R $SYSLOG_REMOTE_HOST:$SYSLOG_REMOTE_PORT"
log_target_msg="$SYSLOG_REMOTE_HOST:$SYSLOG_REMOTE_PORT"
if [ "$SYSLOG_REMOTE_AND_LOCAL" = true ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -L"
log_target_msg="$log_target_msg and stdout"
fi
fi
info "Setting up syslogd - logging to $log_target_msg"
cat > "$supervisor_syslog_conf" <<EOF
[program:syslogd]
user=root
environment=HOME="/root",USER="root",LANG="en_US.UTF-8",PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
command=/usr/local/sbin/syslogd -n $SYSLOG_ARGS
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
autostart=true
autorestart=true
priority=10
EOF
}
# Enable/disable supervisor http server
setup_supervisor_http_server() {
rm -f "$supervisor_http_server_conf"
if [ "$SUPERVISOR_HTTP" = true ]; then
info "Supervisor http server activated"
cat > "$supervisor_http_server_conf" <<EOF
[inet_http_server]
port = :$SUPERVISOR_HTTP_PORT
EOF
chmod 600 "$supervisor_http_server_conf"
if [ -n "$SUPERVISOR_HTTP_USER" ] && [ -n "$SUPERVISOR_HTTP_PASS" ]; then
cat >> "$supervisor_http_server_conf" <<EOF
username = $SUPERVISOR_HTTP_USER
password = $SUPERVISOR_HTTP_PASS
EOF
fi
fi
}
# Enable/disable status http server
setup_status_http_server() {
rm -f "$status_http_server_conf"
rm -f "$status_http_server_updater_conf"
if [ "$STATUS_HTTP" = true ]; then
info "Status http server activated"
touch "$STATUS_HTTP_CONF"
mkdir -p "$STATUS_HTTP_HTDOCS"
if [ ! -d "$STATUS_HTTP_HTDOCS" ]; then
error "Could not create directory $STATUS_HTTP_HTDOCS"
return
fi
cat > "$status_http_server_conf" <<EOF
[program:valheim-status-httpd]
user=root
environment=HOME="/root",USER="root",LANG="en_US.UTF-8",PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
command=/usr/local/bin/httpd -f -p "$STATUS_HTTP_PORT" -h "$STATUS_HTTP_HTDOCS" -c "$STATUS_HTTP_CONF"
stdout_syslog=true
stderr_syslog=true
stdout_logfile_maxbytes=1MB
stderr_logfile_maxbytes=1MB
autostart=true
autorestart=true
startsecs=10
startretries=0
priority=80
EOF
chmod 600 "$status_http_server_conf"
cat > "$status_http_server_updater_conf" <<EOF
[program:valheim-status-updater]
user=root
environment=HOME="/root",USER="root",LANG="en_US.UTF-8",PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
command=/usr/local/bin/valheim-status --update
stdout_syslog=true
stderr_syslog=true
stdout_logfile_maxbytes=1MB
stderr_logfile_maxbytes=1MB
autostart=true
autorestart=true
startsecs=10
startretries=0
priority=70
EOF
chmod 600 "$status_http_server_updater_conf"
fi
}
pre_supervisor_hook() {
if [ -n "$PRE_SUPERVISOR_HOOK" ]; then
info "Running pre supervisor hook: $PRE_SUPERVISOR_HOOK"
eval "$PRE_SUPERVISOR_HOOK"
fi
}
main