@@ -11,16 +11,9 @@ HAPROXY_POST_RESTART_CMD=${HAPROXY_POST_RESTART_CMD:=""}
11
11
HAPROXY_USER_PARAMS=$@
12
12
13
13
# Internal params
14
- HAPROXY_PID_FILE=" /var/run/haproxy.pid"
15
- HAPROXY_CMD=" /usr/local/sbin/haproxy -f ${HAPROXY_CONFIG} ${HAPROXY_USER_PARAMS} -D -p ${HAPROXY_PID_FILE} "
14
+ HAPROXY_CMD=" /usr/local/sbin/haproxy -f ${HAPROXY_CONFIG} -W ${HAPROXY_USER_PARAMS} "
16
15
HAPROXY_CHECK_CONFIG_CMD=" /usr/local/sbin/haproxy -f ${HAPROXY_CONFIG} -c"
17
16
18
- # Iptable commands
19
- LIST_IPTABLES=" iptables --list"
20
- ENABLE_SYN_DROP=" iptables -I INPUT -p tcp -m multiport --dport $HAPROXY_PORTS --syn -j DROP"
21
- DISABLE_SYN_DROP=" iptables -D INPUT -p tcp -m multiport --dport $HAPROXY_PORTS --syn -j DROP"
22
-
23
-
24
17
# ######################################
25
18
# Echo/log function
26
19
# Arguments:
@@ -41,15 +34,6 @@ print_config() {
41
34
printf ' =%.0s' {1..100} && echo
42
35
}
43
36
44
- # Check iptables rules modification capabilities
45
- $LIST_IPTABLES > /dev/null 2>&1
46
- # Exit immidiately in case of any errors
47
- if [[ $? != 0 ]]; then
48
- EXIT_CODE=$? ;
49
- echo " Please enable NET_ADMIN capabilities by passing '--cap-add NET_ADMIN' parameter to docker run command" ;
50
- exit $EXIT_CODE ;
51
- fi
52
-
53
37
# Launch HAProxy.
54
38
# In the default attached haproxy.cfg `web.server` host is used for back-end nodes.
55
39
# If that host doesn't exist in /etc/hosts, create it and point to localhost,
@@ -58,29 +42,26 @@ grep --silent -e "web.server" /etc/hosts || echo "127.0.0.1 web.server" >> /etc/
58
42
59
43
log $HAPROXY_CMD && print_config
60
44
$HAPROXY_CHECK_CONFIG_CMD
61
- $HAPROXY_CMD
62
- # Exit immidiately in case of any errors or when we have interactive terminal
45
+ $HAPROXY_CMD &
46
+
47
+ HAPROXY_PID=$!
48
+
49
+ # Exit immediately in case of any errors or when we have interactive terminal
63
50
if [[ $? != 0 ]] || test -t 0; then exit $? ; fi
64
- log " HAProxy started with $HAPROXY_CONFIG config, pid $( cat $HAPROXY_PID_FILE ) ." && log
51
+ log " HAProxy started with $HAPROXY_CONFIG config, pid $HAPROXY_PID ." && log
65
52
66
53
# Check if config has changed
67
54
# Note: also monitor /etc/hosts where the new back-end hosts might be provided.
68
55
while inotifywait -q -e create,delete,modify,attrib /etc/hosts $HAPROXY_CONFIG $HAPROXY_ADDITIONAL_CONFIG ; do
69
- if [ -f $HAPROXY_PID_FILE ]; then
70
- log " Restarting HAProxy due to config changes..." && print_config
71
- $HAPROXY_CHECK_CONFIG_CMD
72
- $ENABLE_SYN_DROP
73
- sleep 0.2
74
- log " Executing pre-restart hook..."
75
- $HAPROXY_PRE_RESTART_CMD
76
- log " Restarting haproxy..."
77
- $HAPROXY_CMD -sf $( cat $HAPROXY_PID_FILE )
78
- log " Executing post-restart hook..."
79
- $HAPROXY_POST_RESTART_CMD
80
- $DISABLE_SYN_DROP
81
- log " HAProxy restarted, pid $( cat $HAPROXY_PID_FILE ) ." && log
82
- else
83
- log " Error: no $HAPROXY_PID_FILE present, HAProxy exited."
84
- break
85
- fi
56
+ log " Restarting HAProxy due to config changes..." && print_config
57
+ $HAPROXY_CHECK_CONFIG_CMD
58
+ log " Executing pre-restart hook..."
59
+ $HAPROXY_PRE_RESTART_CMD
60
+ log " Restarting haproxy..."
61
+ $HAPROXY_CMD -sf $HAPROXY_PID &
62
+ HAPROXY_PID=$!
63
+ log " Got new PID: $HAPROXY_PID "
64
+ log " Executing post-restart hook..."
65
+ $HAPROXY_POST_RESTART_CMD
66
+ log " HAProxy restarted, pid $HAPROXY_PID ." && log
86
67
done
0 commit comments