From 6d8048b6de945337e1750928c745d0eb90545091 Mon Sep 17 00:00:00 2001 From: Justin Lee Date: Tue, 16 Jan 2018 00:11:01 -0500 Subject: [PATCH] Beta state fix (#538) * Add reload process which writes state file. --- marathon_lb.py | 18 ++++++++---------- reload_haproxy.sh | 5 +++++ run | 4 +++- service/haproxy/run | 3 +-- 4 files changed, 17 insertions(+), 13 deletions(-) create mode 100755 reload_haproxy.sh diff --git a/marathon_lb.py b/marathon_lb.py index 2e61f01d..6a54b45d 100755 --- a/marathon_lb.py +++ b/marathon_lb.py @@ -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() diff --git a/reload_haproxy.sh b/reload_haproxy.sh new file mode 100755 index 00000000..ec1fe01d --- /dev/null +++ b/reload_haproxy.sh @@ -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: diff --git a/run b/run index cef5117e..1a39a2be 100755 --- a/run +++ b/run @@ -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 @@ -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 diff --git a/service/haproxy/run b/service/haproxy/run index 0a5487fa..f894e18a 100755 --- a/service/haproxy/run +++ b/service/haproxy/run @@ -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 \ No newline at end of file +exec $WHICH_HAPROXY -W -f /marathon-lb/haproxy.cfg -x /var/run/haproxy/socket \ No newline at end of file