|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -sed -i "s|NC_PASSWORD_PLACEHOLDER|$NC_HAPROXY_PASSWORD|" /haproxy.cfg |
4 |
| -sed -i "s|TIMEOUT_CONNECT|$TIMEOUT_CONNECT|" /haproxy.cfg |
5 |
| -sed -i "s|TIMEOUT_CLIENT|$TIMEOUT_CLIENT|" /haproxy.cfg |
6 |
| -sed -i "s|TIMEOUT_SERVER|$TIMEOUT_SERVER|" /haproxy.cfg |
| 3 | +if [ ! -f "/haproxy.cfg" ]; then |
7 | 4 |
|
8 |
| -if [ -f "/certs/cert.pem" ]; then |
9 |
| - EX_APPS_COUNT_PADDED=$(printf "%03d" "$EX_APPS_COUNT") |
10 |
| - sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6 ssl crt /certs/cert.pem|" /haproxy.cfg |
11 |
| - 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 |
12 |
| - sed -i "s|EX_APPS_NET_PLACEHOLDER|$EX_APPS_NET|" /haproxy_ex_apps.cfg |
13 |
| - # Chmod certs to be accessible by haproxy |
14 |
| - chmod 644 /certs/cert.pem |
| 5 | + echo "Creating HaProxy config.." |
| 6 | + |
| 7 | + if [ -n "$NC_HAPROXY_PASSWORD_FILE" ] && [ ! -f "$NC_HAPROXY_PASSWORD_FILE" ]; then |
| 8 | + echo "Error: NC_HAPROXY_PASSWORD_FILE is specified but the file does not exist." |
| 9 | + exit 1 |
| 10 | + fi |
| 11 | + |
| 12 | + if [ -n "$NC_HAPROXY_PASSWORD" ] && [ -n "$NC_HAPROXY_PASSWORD_FILE" ]; then |
| 13 | + echo "Error: Only one of NC_HAPROXY_PASSWORD or NC_HAPROXY_PASSWORD_FILE should be specified." |
| 14 | + exit 1 |
| 15 | + fi |
| 16 | + |
| 17 | + if [ -n "$NC_HAPROXY_PASSWORD_FILE" ]; then |
| 18 | + NC_HAPROXY_PASSWORD=$(mkpasswd -m sha-256 < "$NC_HAPROXY_PASSWORD_FILE") |
| 19 | + else |
| 20 | + NC_HAPROXY_PASSWORD=$(echo "$NC_HAPROXY_PASSWORD" | mkpasswd -m sha-256) |
| 21 | + fi |
| 22 | + |
| 23 | + export NC_HAPROXY_PASSWORD |
| 24 | + |
| 25 | + envsubst < /haproxy.cfg.template > /haproxy.cfg |
| 26 | + envsubst < /haproxy_ex_apps.cfg.template > /haproxy_ex_apps.cfg |
| 27 | + |
| 28 | + if [ -f "/certs/cert.pem" ]; then |
| 29 | + EX_APPS_COUNT_PADDED=$(printf "%03d" "$EX_APPS_COUNT") |
| 30 | + sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6 ssl crt /certs/cert.pem|" /haproxy.cfg |
| 31 | + 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 |
| 32 | + sed -i "s|EX_APPS_NET_PLACEHOLDER|$EX_APPS_NET|" /haproxy_ex_apps.cfg |
| 33 | + # Chmod certs to be accessible by haproxy |
| 34 | + chmod 644 /certs/cert.pem |
| 35 | + else |
| 36 | + sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6|" /haproxy.cfg |
| 37 | + fi |
15 | 38 | else
|
16 |
| - sed -i "s|BIND_ADDRESS_PLACEHOLDER|bind $BIND_ADDRESS:$HAPROXY_PORT v4v6|" /haproxy.cfg |
| 39 | + echo "HaProxy config already present." |
17 | 40 | fi
|
18 | 41 |
|
19 | 42 | echo "HaProxy config:"
|
|
0 commit comments