Skip to content

Commit

Permalink
Beta state fix (#538)
Browse files Browse the repository at this point in the history
* Add reload process which writes state file.
  • Loading branch information
Justin Lee authored Jan 16, 2018
1 parent 95ee79d commit 6d8048b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
18 changes: 8 additions & 10 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,15 @@ def config(apps, groups, bind_http_https, ssl_certs, templater,
if "expose-fd listeners" not in config:
if "stats socket /var/run/haproxy/socket" in config:
logger.debug("Appending 'expose-fd listeners' to stats socket")
config = config.replace("stats socket /var/run/haproxy/socket",
"stats socket /var/run/haproxy/socket expose-fd listeners")
o = "stats socket /var/run/haproxy/socket"
n = "stats socket /var/run/haproxy/socket expose-fd listeners"
config = config.replace(o, n)
else:
logger.debug(
("Adding '"
"stats socket /var/run/haproxy/socket expose-fd listeners"
"' after 'global' line"))
config = config.replace("global",
("global\n"
" stats socket /var/run/haproxy/socket expose-fd listeners"),
1)
o = "global"
n = ("global\n"
" stats socket /var/run/haproxy/socket expose-fd listeners")
logger.debug("Creating new expose-fd listeners socket config")
config = config.replace(o, n, 1)

userlists = str()
frontends = str()
Expand Down
5 changes: 5 additions & 0 deletions reload_haproxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

socat /var/run/haproxy/socket - <<< "show servers state" > /var/state/haproxy/global

# "sv reload ${HAPROXY_SERVICE}" will be added here by /marathon-lb/run:
4 changes: 3 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ for arg in "$@"; do
ARGS="$ARGS $escaped"
done

echo "sv reload ${HAPROXY_SERVICE}" >> /marathon-lb/reload_haproxy.sh

cat > $LB_SERVICE/run << EOF
#!/bin/sh
exec 2>&1
Expand All @@ -127,7 +129,7 @@ exec /marathon-lb/marathon_lb.py \
--syslog-socket $SYSLOG_SOCKET \
--haproxy-config /marathon-lb/haproxy.cfg \
--ssl-certs "${SSL_CERTS}" \
--command "sv reload ${HAPROXY_SERVICE}" \
--command "/marathon-lb/reload_haproxy.sh" \
$ARGS
EOF
chmod 755 $LB_SERVICE/run
Expand Down
3 changes: 1 addition & 2 deletions service/haproxy/run
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
exec 2>&1
export PIDFILE="/tmp/haproxy.pid"
WHICH_HAPROXY=$(which haproxy)

mkdir -p /var/state/haproxy
mkdir -p /var/run/haproxy

exec $WHICH_HAPROXY -W -p $PIDFILE -f /marathon-lb/haproxy.cfg -x /var/run/haproxy/socket -sf
exec $WHICH_HAPROXY -W -f /marathon-lb/haproxy.cfg -x /var/run/haproxy/socket

0 comments on commit 6d8048b

Please sign in to comment.