-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
65 lines (53 loc) · 2.12 KB
/
start.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
#!/bin/sh
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
if [ ! -f "/haproxy.cfg" ]; then
echo "Creating HaProxy config.."
if [ -n "$NC_HAPROXY_PASSWORD_FILE" ] && [ ! -f "$NC_HAPROXY_PASSWORD_FILE" ]; then
echo "Error: NC_HAPROXY_PASSWORD_FILE is specified but the file does not exist."
exit 1
fi
if [ -n "$NC_HAPROXY_PASSWORD" ] && [ -n "$NC_HAPROXY_PASSWORD_FILE" ]; then
echo "Error: Only one of NC_HAPROXY_PASSWORD or NC_HAPROXY_PASSWORD_FILE should be specified."
exit 1
fi
if [ -n "$NC_HAPROXY_PASSWORD_FILE" ]; then
if [ -s "$NC_HAPROXY_PASSWORD_FILE" ]; then
NC_HAPROXY_PASSWORD=$(mkpasswd -m sha-256 < "$NC_HAPROXY_PASSWORD_FILE")
else
echo "Error: NC_HAPROXY_PASSWORD_FILE is specified but is empty."
exit 1
fi
elif [ -n "$NC_HAPROXY_PASSWORD" ]; then
NC_HAPROXY_PASSWORD=$(echo "$NC_HAPROXY_PASSWORD" | mkpasswd -m sha-256)
else
echo "Error: Either NC_HAPROXY_PASSWORD_FILE or NC_HAPROXY_PASSWORD must be set and contain a password."
exit 1
fi
export NC_HAPROXY_PASSWORD
envsubst < /haproxy.cfg.template > /haproxy.cfg
envsubst < /haproxy_ex_apps.cfg.template > /haproxy_ex_apps.cfg
if [ -f "/certs/cert.pem" ]; then
EX_APPS_COUNT_PADDED=$(printf "%03d" "$EX_APPS_COUNT")
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6 ssl crt /certs/cert.pem|" /haproxy.cfg
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:23000-23$EX_APPS_COUNT_PADDED v4v6 ssl crt /certs/cert.pem|" /haproxy_ex_apps.cfg
sed -i "s|EX_APPS_NET_PLACEHOLDER|$EX_APPS_NET|" /haproxy_ex_apps.cfg
# Chmod certs to be accessible by haproxy
chmod 644 /certs/cert.pem
else
sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6|" /haproxy.cfg
fi
else
echo "HaProxy config already present."
fi
echo "HaProxy config:"
if [ -f "/certs/cert.pem" ]; then
cat /haproxy.cfg
cat /haproxy_ex_apps.cfg
haproxy -f /haproxy.cfg -f /haproxy_ex_apps.cfg -db
else
cat /haproxy.cfg
haproxy -f /haproxy.cfg -db
fi
echo "HaProxy quit unexpectedly"
exit 1