-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·66 lines (58 loc) · 1.33 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
#!/bin/bash
set -e
WAIT_DAYS=${WAIT_DAYS:-7}
TARGET_HOUR=${TARGET_HOUR:-3}
function request_certs {
if [ ! -f get-certs.sh.sha1 ]; then
sha1sum get-certs.sh > get-certs.sh.sha1
bash get-certs.sh
else
exec 3>&2
exec 2> /dev/null
result=$(sha1sum -c get-certs.sh.sha1 | cut -d: -f 2 | xargs 2>/dev/null)
exec 2>&3
if [ "$result" != "OK" ]; then
echo "* Changes detected"
bash get-certs.sh
fi
fi
sha1sum get-certs.sh > get-certs.sh.sha1
}
function start_haproxy {
echo -e "\n * Starting HAProxy"
haproxy -D -p /var/run/haproxy.pid -f haproxy.cfg
echo -e " ...done.\n"
}
function stop_haproxy {
echo " * Stopping HAProxy"
for pid in $(cat /var/run/haproxy.pid); do
kill $pid
done
rm -f /var/run/haproxy.pid
echo -e " ...done.\n"
}
function renew_certs {
certbot renew --standalone
}
function wait_interval {
hour=$(date +"%k")
if [ $hour -gt $TARGET_HOUR ]; then
extra_hours=$((24-hour+TARGET_HOUR))
else
extra_hours=$((TARGET_HOUR-hour))
fi
echo -e "\n * Waiting $WAIT_DAYS days and $extra_hours hours"
sleep $((WAIT_DAYS*86400+extra_hours*3600))
echo -e " ...done.\n"
}
mkdir -p /opt/haproxy/ssl
python3 gen_conf.py
request_certs
cat haproxy.cfg
while true; do
bash load-certs.sh
start_haproxy
wait_interval
stop_haproxy
renew_certs
done