[WORKER] Support cleaner HAProxy config reloading
Stopping and restarting the HAProxy service will rudely terminate any active sessions in HAProxy. This new method allows existing connections to finish whatever they are doing while the configuration file is reloaded. Change-Id: Ife5d3ccc66349ea3393541768f12aedddb5ac5c8
This commit is contained in:
committed by
Andrew Hutchings
parent
fab4198f22
commit
c5b094d3dc
@@ -19,6 +19,9 @@ class FakeOSServices(ServicesBase):
|
|||||||
def service_start(self):
|
def service_start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def service_reload(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def write_config(self, config_str):
|
def write_config(self, config_str):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -39,6 +42,9 @@ class FakeFaultingOSServices(ServicesBase):
|
|||||||
def service_start(self):
|
def service_start(self):
|
||||||
raise Exception("fault")
|
raise Exception("fault")
|
||||||
|
|
||||||
|
def service_reload(self):
|
||||||
|
raise Exception("fault")
|
||||||
|
|
||||||
def service_restart(self):
|
def service_restart(self):
|
||||||
raise Exception("fault")
|
raise Exception("fault")
|
||||||
|
|
||||||
|
|||||||
@@ -336,8 +336,7 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
self.ossvc.write_config(self._config_to_string())
|
self.ossvc.write_config(self._config_to_string())
|
||||||
self.ossvc.service_stop()
|
self.ossvc.service_reload()
|
||||||
self.ossvc.service_start()
|
|
||||||
|
|
||||||
def suspend(self):
|
def suspend(self):
|
||||||
self.ossvc.service_stop()
|
self.ossvc.service_stop()
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class ServicesBase:
|
|||||||
""" Start the HAProxy service. """
|
""" Start the HAProxy service. """
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def service_reload(self):
|
||||||
|
""" Reload the HAProxy config file. """
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
def write_config(self, config_str):
|
def write_config(self, config_str):
|
||||||
""" Write the HAProxy configuration file. """
|
""" Write the HAProxy configuration file. """
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|||||||
@@ -58,6 +58,22 @@ class UbuntuServices(ServicesBase):
|
|||||||
raise Exception("%s does not exist. Start failed." %
|
raise Exception("%s does not exist. Start failed." %
|
||||||
self._haproxy_pid)
|
self._haproxy_pid)
|
||||||
|
|
||||||
|
def service_reload(self):
|
||||||
|
"""
|
||||||
|
Reload the HAProxy config file in a non-intrusive manner.
|
||||||
|
|
||||||
|
This assumes that /etc/init.d/haproxy is using the -sf option
|
||||||
|
to the haproxy process.
|
||||||
|
"""
|
||||||
|
cmd = '/usr/bin/sudo -n /usr/sbin/service haproxy reload'
|
||||||
|
try:
|
||||||
|
subprocess.check_output(cmd.split())
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
raise Exception("Failed to reload HAProxy config: %s" % e)
|
||||||
|
if not os.path.exists(self._haproxy_pid):
|
||||||
|
raise Exception("%s does not exist. Reload failed." %
|
||||||
|
self._haproxy_pid)
|
||||||
|
|
||||||
def sudo_copy(self, from_file, to_file):
|
def sudo_copy(self, from_file, to_file):
|
||||||
cmd = "/usr/bin/sudo -n /bin/cp %s %s" % (from_file, to_file)
|
cmd = "/usr/bin/sudo -n /bin/cp %s %s" % (from_file, to_file)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user