From 5038c96915aebbd279ec65f89eeee2435be42a23 Mon Sep 17 00:00:00 2001 From: Justin Lee Date: Fri, 29 Dec 2017 12:55:38 -0500 Subject: [PATCH] Handle legacy HAPROXY_HEAD (daemon and expose-fd listeners) For users that have existing custom HAPROXY_HEAD settings, make adjustments to meet the new zero downtime reload settings. Specifically: - remove (comment out) the 'daemon' keyword (in the 'global' block) - add 'expose-fd listeners' to the stats socket These corrections are rudimentary; ideally, customers should fix their HAPROXY_HEAD settings. --- marathon_lb.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/marathon_lb.py b/marathon_lb.py index c864b911..2e61f01d 100755 --- a/marathon_lb.py +++ b/marathon_lb.py @@ -345,6 +345,28 @@ def config(apps, groups, bind_http_https, ssl_certs, templater, https_frontends = templater.haproxy_https_frontend_head.format( sslCerts=" ".join(map(lambda cert: "crt " + cert, _ssl_certs)) ) + # This should handle situations where customers have a custom HAPROXY_HEAD + # that includes the 'daemon' flag: + if 'daemon' in config: + logger.debug("Commenting out daemon setting") + config = config.replace("daemon", "# daemon", 1) + + # This should handle situations where customers have a custom HAPROXY_HEAD + # that does not yet expose the listeners file descriptor + 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") + 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) userlists = str() frontends = str()