From 6f44509dcb4faa4bc0340ae138c86d77ef2e2c84 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 24 Jun 2020 18:40:45 +0900 Subject: [PATCH] Make sure failed containers get stopped by systemd When the main PID (i.e., common) of a container is killed because of some reasons, systemd won't execute ExecStop command. Current podman doesn't detect this failure ang recognize that container is still running and this causes failure when systemd tries to restart the container. This patch introduces ExecStopPost configuration into systemd unit files so that stop operation is executed even when a container fails because of killed main process. The stale container should be cleaned up by ExecStopPost task before systemd tries to restart it. Note that the similar change has been introcuded to "podman generate systemd" command already[1]. [1] https://github.com/containers/libpod/commit/e5c3432944245a740ed443803c654dcc9c3757f0 Change-Id: Ie2cb3bb63138b70019f86b88066697e98e333669 Closes-Bug: #1884866 (cherry picked from commit b8f412d81cf3bbbb4b3d0a420d76e91a3c620799) --- paunch/tests/test_utils_systemd.py | 1 + paunch/utils/systemd.py | 1 + 2 files changed, 2 insertions(+) diff --git a/paunch/tests/test_utils_systemd.py b/paunch/tests/test_utils_systemd.py index 1e258a9..766ab56 100644 --- a/paunch/tests/test_utils_systemd.py +++ b/paunch/tests/test_utils_systemd.py @@ -41,6 +41,7 @@ class TestUtilsSystemd(base.TestCase): self.assertIn('Wants=something.service', unit) self.assertIn('Restart=always', unit) self.assertIn('ExecStop=/usr/bin/podman stop -t 15 my_app', unit) + self.assertIn('ExecStopPost=/usr/bin/podman stop -t 15 my_app', unit) self.assertIn('PIDFile=/var/run/my_app.pid', unit) mock_chmod.assert_has_calls([mock.call(sysd_unit_f, 420)]) diff --git a/paunch/utils/systemd.py b/paunch/utils/systemd.py index 0583b42..4c70171 100644 --- a/paunch/utils/systemd.py +++ b/paunch/utils/systemd.py @@ -101,6 +101,7 @@ Restart=%(restart)s ExecStart=%(start_cmd)s ExecReload=/usr/bin/podman kill --signal HUP %(name)s ExecStop=/usr/bin/podman stop -t %(stop_grace_period)s %(name)s +ExecStopPost=/usr/bin/podman stop -t %(stop_grace_period)s %(name)s KillMode=none Type=forking PIDFile=/var/run/%(name)s.pid