-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-entrypoint-override.sh
executable file
·53 lines (38 loc) · 1.09 KB
/
docker-entrypoint-override.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
#!/bin/bash
set -e
trap "stop; exit 0;" SIGTERM SIGINT
# handler for SIGINT & SIGITEM
stop() {
echo "SIGTERM caught, terminating <haproxy & keepalived> process..."
# terminate haproxy
h_pid=$(pidof haproxy)
kill -TERM $h_pid > /dev/null 2>&1
echo "HAProxy had terminated."
# terminate keepalived
kill -TERM $(cat /var/run/vrrp.pid)
kill -TERM $(cat /var/run/keepalived.pid)
echo "Keepalived had terminated."
echo "haproxy-keepalived service instance is successfuly terminated!"
}
# init haproxy & keepalived conf
/bin/bash -c /haproxy/init_haproxy_conf.sh
/bin/bash -c /keepalived/init_keepalived_conf.sh
# exec haproxy entrypoint
exec /docker-entrypoint.sh "$@" &
# start keepalived
exec /start_keepalived.sh "$@" &
# wait <haproxy & keepalived> service started
sleep 10
while true; do
h_pid=$(pidof haproxy)
# if h_pid is non-null, sleep; otherwise, break the cycle;
while [ -n "$h_pid" ]; do
# echo "haproxy alive sleep"
sleep 1
done
break
done
# if haproxy is crashed, exit entrypoint
wait $h_pid
echo "Haproxy service is no longer running, exiting..."
exit 0;