Skip to content

Commit 97a6f16

Browse files
authored
Merge pull request #27 from MiniCodeMonkey/master
Updated from haproxy 1.9 to 2.0 and enabled logging to stdout
2 parents 13ceaaa + 226b3b6 commit 97a6f16

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM centos:centos7
22

3-
ENV HAPROXY_MJR_VERSION=1.9 \
4-
HAPROXY_VERSION=1.9.2 \
3+
ENV HAPROXY_MJR_VERSION=2.0 \
4+
HAPROXY_VERSION=2.0.8 \
55
HAPROXY_CONFIG='/etc/haproxy/haproxy.cfg' \
66
HAPROXY_ADDITIONAL_CONFIG='' \
77
HAPROXY_PRE_RESTART_CMD='' \
@@ -27,7 +27,7 @@ RUN \
2727
tar -zxvf /tmp/haproxy.tgz -C /tmp && \
2828
cd /tmp/haproxy-* && \
2929
make \
30-
TARGET=linux2628 USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_PCRE=1 USE_PCRE_JIT=1 \
30+
TARGET=linux-glibc USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_PCRE=1 USE_PCRE_JIT=1 \
3131
USE_OPENSSL=1 SSL_INC=/usr/include SSL_LIB=/usr/lib ADDLIB=-ldl \
3232
CFLAGS="-O2 -g -fno-strict-aliasing -DTCP_USER_TIMEOUT=18" && \
3333
make install && \

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Example:
4747

4848
```bash
4949
docker run -ti \
50-
--cap-add NET_ADMIN \
5150
-p 80:80 \
5251
-p 443:443 \
5352
million12/haproxy
@@ -57,7 +56,6 @@ docker run -ti \
5756

5857
```bash
5958
docker run -d \
60-
--cap-add NET_ADMIN \
6159
-p 80:80 \
6260
-v /my-haproxy.cfg:/etc/haproxy/haproxy.cfg \
6361
million12/haproxy \
@@ -70,7 +68,6 @@ Note: in this case config is mounted to its default location, so you don't need
7068

7169
```bash
7270
docker run -d \
73-
--cap-add NET_ADMIN \
7471
-p 80:80 \
7572
-e HAPROXY_ADDITIONAL_CONFIG='/etc/haproxy/custom1 /etc/haproxy/custom2' \
7673
million12/haproxy

container-files/bootstrap.sh

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@ HAPROXY_POST_RESTART_CMD=${HAPROXY_POST_RESTART_CMD:=""}
1111
HAPROXY_USER_PARAMS=$@
1212

1313
# 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}"
1615
HAPROXY_CHECK_CONFIG_CMD="/usr/local/sbin/haproxy -f ${HAPROXY_CONFIG} -c"
1716

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-
2417
#######################################
2518
# Echo/log function
2619
# Arguments:
@@ -41,15 +34,6 @@ print_config() {
4134
printf '=%.0s' {1..100} && echo
4235
}
4336

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-
5337
# Launch HAProxy.
5438
# In the default attached haproxy.cfg `web.server` host is used for back-end nodes.
5539
# 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/
5842

5943
log $HAPROXY_CMD && print_config
6044
$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
6350
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
6552

6653
# Check if config has changed
6754
# Note: also monitor /etc/hosts where the new back-end hosts might be provided.
6855
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
8667
done

0 commit comments

Comments
 (0)