Commit 8bafb574 authored by segfault's avatar segfault

Check if systemd service is successfully started

parent 7a7dd9b6
......@@ -2,6 +2,7 @@ from logging import getLogger
import sh
import subprocess
from threading import Thread
import time
from onionkit.exceptions import MonitorError
from onionkit.service_status import Status
......@@ -9,6 +10,11 @@ from onionkit.service_status import Status
logger = getLogger()
class SystemdError(Exception):
pass
START_TIMEOUT = 5
STOP_MONITOR_TIMEOUT = 1
......@@ -35,6 +41,16 @@ class SystemdManager(object):
finally:
self.restarting = False
# Make sure that the service was successfully started
start_time = time.perf_counter()
while time.perf_counter() - start_time < START_TIMEOUT:
if self.is_running():
logger.debug("Successfully started %s", self.id)
return
time.sleep(0.2)
raise SystemdError("Failed to start %s (timeout: %s)", self.id, START_TIMEOUT)
def stop(self):
logger.debug("Stopping %s", self.id)
sh.systemctl("-M", self.container, "stop", self.service)
......
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