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] e5c3432944

Change-Id: Idb8be98f83f95ae536762f79809aa375f04e56ab
Closes-Bug: #1884866
This commit is contained in:
Takashi Kajinami 2020-06-24 11:19:41 +09:00
parent d6fb5548d2
commit 77b4f66504
1 changed files with 1 additions and 0 deletions

View File

@ -14,6 +14,7 @@ ExecReload=/usr/bin/podman kill --signal HUP {{ lookup('dict', container_data_un
ExecStop=-/usr/bin/podman exec {{ lookup('dict', container_data_unit).key }} {{ lookup('dict', container_data_unit).value.pre_stop_exec }}
{% endif %}
ExecStop=/usr/bin/podman stop -t {{ lookup('dict', container_data_unit).value.stop_grace_period | default(10) | int }} {{ lookup('dict', container_data_unit).key }}
ExecStopPost=/usr/bin/podman stop -t {{ lookup('dict', container_data_unit).value.stop_grace_period | default(10) | int }} {{ lookup('dict', container_data_unit).key }}
KillMode=none
Type=forking
PIDFile=/var/run/{{ lookup('dict', container_data_unit).key }}.pid