-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·67 lines (52 loc) · 1.13 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
cleanup() {
echo "caught Signal ... stopping nginx ..."
nginx -s stop
echo "done."
exit 0
}
trap cleanup HUP INT QUIT TERM
renew() {
touch do_not_stop
nginx -s quit
for domain in $(ls /renew-routines); do
./renew-routines/${domain}
done
nginx
rm do_not_stop
}
renew_maintainer() {
renew
while sleep 7d; do
renew
done
}
secure_ssl_files() {
chown -R root:root /ssl-cert
chmod -R 600 /ssl-cert
}
if [[ -z "$@" ]]; then
# https://gist.github.com/tsaarni/14f31312315b46f06e0f1ecc37146bf3
mkdir -p -m 600 /etc/nginx/ssl
echo -e ".\n.\n.\n\n.\n.\n.\n" | openssl req -x509 -newkey ec:<(openssl ecparam -name secp384r1) -nodes -days 365 -out /etc/nginx/ssl/cert.pem -keyout /etc/nginx/ssl/privkey.pem
echo
secure_ssl_files
nginx
renew_maintainer &
while sleep 30s; do
ps | grep nginx | grep -q -v grep
nginx=$?
if [[ ! -f ./do_not_stop && $nginx != 0 ]]; then
echo "nginx stopped working!"
exit 1
fi
done
elif [[ "$@" == "reload" ]]; then
secure_ssl_files
nginx -s reload
exit $?
elif [[ "$@" == "renew" ]]; then
renew
exit $?
fi
exec "$@"