Skip to content

Commit 6b6eecc

Browse files
ustcweizhouweizhouapache
authored andcommitted
LB: verify haproxy config before haproxy restart/reload
1 parent 17329d2 commit 6b6eecc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

systemvm/debian/opt/cloud/bin/cs/CsLoadBalancer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def process(self):
5151
file1.commit()
5252
file2 = CsFile(HAPROXY_CONF_P)
5353
if not file2.compareOrder(file1):
54+
# Verify new haproxy config before haproxy restart/reload
55+
haproxy_err = self._verify_haproxy_config(HAPROXY_CONF_T)
56+
if haproxy_err:
57+
raise Exception("haproxy config is invalid with error \n%s" % haproxy_err);
58+
5459
CsHelper.copy(HAPROXY_CONF_T, HAPROXY_CONF_P)
5560

5661
proc = CsProcess(['/run/haproxy.pid'])
@@ -131,3 +136,11 @@ def _create_pem_for_sslcert(self, ssl_certs):
131136
for f in listdir(SSL_CERTS_DIR):
132137
if f not in cert_names:
133138
CsHelper.execute("rm -rf %s/%s" % (SSL_CERTS_DIR, f))
139+
140+
def _verify_haproxy_config(self, config):
141+
ret = CsHelper.execute2("haproxy -c -f %s" % config)
142+
if ret.returncode:
143+
stdout, stderr = ret.communicate()
144+
logging.error("haproxy config is invalid with error: %s" % stderr)
145+
return stderr
146+
return ""

0 commit comments

Comments
 (0)