-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·48 lines (40 loc) · 1.36 KB
/
docker-entrypoint.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
#!/usr/bin/env bash
set -Eeuo pipefail
trap "exit 1;" SIGINT SIGTERM
#Check environvent variables
if [ -z "$DOMAIN" ]; then
echo "No domain specified";
exit 1;
fi
if [ -z "$CERT" ]; then
echo "No certificate path specified";
exit 1;
fi
#Generate config from template
CONFIG=/etc/nginx/conf.d/default.conf
function template2conf {
export example_com=$DOMAIN example__com=${DOMAIN//./\\.} ssl_certificate=$CERT/fullchain.pem ssl_certificate_key=$CERT/privkey.pem;
envsubst '$example_com,$example__com,$ssl_certificate,$ssl_certificate_key' < /etc/nginx/conf.d/templates/$1 > $CONFIG;
}
#If there are no certificates, use a dummy server to obtain them.
if [ -f "$CERT/fullchain.pem" ] && [ -f "$CERT/privkey.pem" ]; then
template2conf static.conf
else
template2conf dummy.conf
fi;
if [ "$1" = 'nginx' ]; then
#Wait for certificates and nginx.
while [ ! -f "$CERT/fullchain.pem" ] || [ ! -f "$CERT/privkey.pem" ] || [ ! -e /var/run/nginx.pid ]; do
sleep 1;
done;
template2conf static.conf;
nginx -s reload;
#Monitor changes in certificates.
inotifywait -qm -e modify -e close_write -e move -e move_self -e create $CERT | while read -s; do
while read -s -t 10; do :; done;
if [ -f "$CERT/fullchain.pem" ] && [ -f "$CERT/privkey.pem" ]; then
nginx -s reload;
fi;
done;
fi &
exec "$@"