From a783594fd40cb4593b236bdd9377c42cb1537393 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Thu, 14 Oct 2021 16:42:35 +0200 Subject: [PATCH] Wrap stopping podman -t with systemd timeouts Currently with KillMode=none, if podman -t hangs, the command repeats leaving the process and its cgroup around. But if a stop/start command hangs, we should not start another one. Instead time it out properly via TimeoutStopSec set to the 2x of the timeout given to the managed podman action. Then if it expires, kill its cgroup all the way (KillMode=control-group is a default) before rerunning the same operation. Also note that using KilMode process is not recommended by systemd man pages. Increase the grace stop timeout defaults 10->42s to align it with: https://github.com/containers/podman/pull/8889 Closes-bug: #1945791 Change-Id: Iefe861f91cefe2a9cf773cae98b2440566ae8b5e Signed-off-by: Bogdan Dobrelya (cherry picked from commit badd5a3c10f0af9e1c69a9b88064e743a36d4f53) --- paunch/utils/systemd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paunch/utils/systemd.py b/paunch/utils/systemd.py index b17150a..f5a5ccd 100644 --- a/paunch/utils/systemd.py +++ b/paunch/utils/systemd.py @@ -83,6 +83,7 @@ def service_create(container, cconfig, sysdir=constants.SYSTEMD_DIR, log=None): 'wants': wants, 'restart': restart, 'stop_grace_period': stop_grace_period, + 'kill_cgroup_period': 2 * stop_grace_period, 'sys_exec': '\n'.join(['%s=%s' % (x, y) for x, y in sys_exec.items()]), } # Ensure we don't have some trailing .requires directory and content for @@ -103,7 +104,7 @@ def service_create(container, cconfig, sysdir=constants.SYSTEMD_DIR, log=None): ExecStop=/usr/bin/podman stop -t %(stop_grace_period)s %(name)s ExecStopPost=/usr/bin/podman stop -t %(stop_grace_period)s %(name)s SuccessExitStatus=137 142 143 -KillMode=none +TimeoutStopSec=%(kill_cgroup_period)s Type=forking PIDFile=/var/run/%(name)s.pid %(sys_exec)s