Commit f93e0e42 authored by segfault's avatar segfault

Try stopping container with SIGKILL if doesn't stop within timeout

parent f6b0d909
......@@ -16,6 +16,8 @@ logger = getLogger(__name__)
START_TIMEOUT = 5
# This will be waited for twice, once when trying to stop container gracefully
# and once after sending SIGKILL to all container processes
STOP_TIMEOUT = 5
APT_UPDATE_TIMEOUT = 60
APT_INSTALL_TIMEOUT = 60
......@@ -106,6 +108,15 @@ class ContainerManager(object):
sh.machinectl("stop", self.name)
start_time = time.perf_counter()
while time.perf_counter() - start_time < STOP_TIMEOUT:
if not self.is_running():
return
time.sleep(0.2)
logger.warning("Failed to stop %r gracefully (timeout %s). Sending SIGKILL to all container processes.", self.name, STOP_TIMEOUT)
sh.machinectl("kill", "--signal=SIGKILL", self.name)
start_time = time.perf_counter()
while time.perf_counter() - start_time < STOP_TIMEOUT:
if not self.is_running():
......
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