diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 480f08eb22..427571a5fe 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -1021,7 +1021,7 @@ a `$name.pod` file creates a `$name-pod.service` unit and a `systemd-$name` Podm Valid options for `[Pod]` are listed below: -| **[Pod] options** | **podman pod create equivalent** | +| **[Pod] options** | **podman pod create equivalent** | |-------------------------------------|----------------------------------------| | AddHost=example\.com:192.168.10.11 | --add-host example.com:192.168.10.11 | | ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | @@ -1042,6 +1042,7 @@ Valid options for `[Pod]` are listed below: | PublishPort=8080:80 | --publish 8080:80 | | ServiceName=name | Name the systemd unit `name.service` | | ShmSize=100m | --shm-size=100m | +| StopTimeout=20 | --time=20 | | SubGIDMap=gtest | --subgidname=gtest | | SubUIDMap=utest | --subuidname=utest | | UIDMap=0:10000:10 | --uidmap=0:10000:10 | @@ -1210,6 +1211,12 @@ Size of /dev/shm. This is equivalent to the Podman `--shm-size` option and generally has the form `number[unit]` +### `StopTimeout=` + +Sets the time in seconds to wait for the pod to gracefully stop. +This value is equivalent to the `--time` argument in the podman `pod stop` command when the service is stopped. +After this period expires, any running containers in the pod are forcibly killed. + ### `SubGIDMap=` Create the pod in a new user namespace using the map with name in the /etc/subgid file. diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index c077043f9d..80eb2f0fa1 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -485,6 +485,7 @@ var ( KeyRemapUsers: true, KeyServiceName: true, KeyShmSize: true, + KeyStopTimeout: true, KeySubGIDMap: true, KeySubUIDMap: true, KeyUIDMap: true, @@ -1552,9 +1553,13 @@ func ConvertPod(podUnit *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isU execStop := createBasePodmanCommand(podUnit, PodGroup) execStop.add("pod", "stop") + stopTimeout := "10" + if value, ok := podUnit.Lookup(PodGroup, KeyStopTimeout); ok { + stopTimeout = value + } execStop.add( "--ignore", - "--time=10", + fmt.Sprintf("--time=%s", stopTimeout), podName, ) service.AddCmdline(ServiceGroup, "ExecStop", execStop.Args) diff --git a/test/e2e/quadlet/stoptimeout.pod b/test/e2e/quadlet/stoptimeout.pod new file mode 100644 index 0000000000..3162612fd1 --- /dev/null +++ b/test/e2e/quadlet/stoptimeout.pod @@ -0,0 +1,8 @@ +## assert-podman-stop-args --time=20 + +[Unit] +Description=A pod with a custom stop timeout + +[Pod] +PodName=test-pod +StopTimeout=20 diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 44dad370d5..30e38cdf4c 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -1093,6 +1093,7 @@ BOGUS=foo Entry("Pod - Remap keep-id", "remap-keep-id.pod"), Entry("Pod - Remap manual", "remap-manual.pod"), Entry("Pod - Shm Size", "shmsize.pod"), + Entry("Pod - StopTimeout", "stoptimeout.pod"), Entry("Pod - Service Environment", "service-environment.pod"), )