-
Notifications
You must be signed in to change notification settings - Fork 188
/
haproxy-entrypoint.sh
40 lines (32 loc) · 1.15 KB
/
haproxy-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
#!/bin/sh
set -e
log() {
local message="$1"
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")
echo "{\"time\":\"${date}\", \"message\": \"${message}\"}"
}
if [ "$1" = 'haproxy' ]; then
if [ ! -f '/etc/haproxy/pxc/haproxy.cfg' ]; then
log /opt/percona/haproxy.cfg /etc/haproxy/pxc
cp /opt/percona/haproxy.cfg /etc/haproxy/pxc
fi
custom_conf='/etc/haproxy-custom/haproxy-global.cfg'
if [ -f "$custom_conf" ]; then
log "haproxy -c -f $custom_conf -f /etc/haproxy/pxc/haproxy.cfg"
haproxy -c -f $custom_conf -f /etc/haproxy/pxc/haproxy.cfg || EC=$?
if [ -n "$EC" ]; then
log "The custom config $custom_conf is not valid and will be ignored."
fi
fi
haproxy_opt='-W -db '
if [ -f "$custom_conf" -a -z "$EC" ]; then
haproxy_opt+="-f $custom_conf "
else
haproxy_opt+='-f /opt/percona/haproxy-global.cfg '
fi
haproxy_opt+='-f /etc/haproxy/pxc/haproxy.cfg -p /etc/haproxy/pxc/haproxy.pid -S /etc/haproxy/pxc/haproxy-main.sock '
fi
log 'test -e /opt/percona/hookscript/hook.sh && source /opt/percona/hookscript/hook.sh'
test -e /opt/percona/hookscript/hook.sh && source /opt/percona/hookscript/hook.sh
log "$@ $haproxy_opt"
exec "$@" $haproxy_opt