Commit 7a7dd9b6 authored by segfault's avatar segfault

Fix monitor setting error state when service is restarted

parent 21d87203
......@@ -9,7 +9,7 @@ from onionkit.service_status import Status
logger = getLogger()
STOP_WATCHER_TIMEOUT = 1
STOP_MONITOR_TIMEOUT = 1
class SystemdManager(object):
......@@ -24,10 +24,16 @@ class SystemdManager(object):
self.id = '%s/%s' % (self.container, self.service)
self.monitor = None # type: subprocess.Popen
self.parser = None # type: Thread
self.restarting = False
def restart(self):
logger.debug("Restarting %s", self.id)
sh.systemctl("-M", self.container, "restart", self.service)
# The restarting attribute tells the monitor to ignore it if the service is stopped
self.restarting = True
try:
sh.systemctl("-M", self.container, "restart", self.service)
finally:
self.restarting = False
def stop(self):
logger.debug("Stopping %s", self.id)
......@@ -80,9 +86,9 @@ class SystemdManager(object):
self.monitor.kill()
try:
self.monitor.wait(STOP_WATCHER_TIMEOUT)
self.monitor.wait(STOP_MONITOR_TIMEOUT)
except subprocess.TimeoutExpired:
raise MonitorError("Failed to stop monitor %s (timeout: %s)" % (self.id, STOP_WATCHER_TIMEOUT))
raise MonitorError("Failed to stop monitor %s (timeout: %s)" % (self.id, STOP_MONITOR_TIMEOUT))
def _parse_monitor_output(self):
while True:
......@@ -118,6 +124,10 @@ class SystemdManager(object):
return message
def _update_status(self):
if self.restarting:
# The service is currently being restarted, so we don't care if the service is being stopped
return
active_state, sub_state = self._get_state()
if active_state in ("inactive", "failed") or sub_state == "exited":
# Get systemctl status output for debugging
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment