summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/pods.go
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@redhat.com>2022-05-03 10:15:55 +0200
committerValentin Rothberg <vrothberg@redhat.com>2022-05-03 15:28:50 +0200
commit6e2e3a78ed1d05ee5f23f65b814e8135021961dd (patch)
treeb63078a6aa0fa1b163f9c7e7a94e4f05a91be427 /pkg/systemd/generate/pods.go
parent3ac5cec086e1ee1f11fabfd8a8f0aa8cf9f371f5 (diff)
downloadpodman-6e2e3a78ed1d05ee5f23f65b814e8135021961dd.tar.gz
podman-6e2e3a78ed1d05ee5f23f65b814e8135021961dd.tar.bz2
podman-6e2e3a78ed1d05ee5f23f65b814e8135021961dd.zip
generate systemd: pods: set exit policy
Unless specified in the create command of the pod, enforce the exit policy to "stop". With "stop", a pod is stopped when the last container exits and does not continue running. This behavior integrates much better into systemd which is now able to tell whether the service running as pod is actually running/active or not. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
Diffstat (limited to 'pkg/systemd/generate/pods.go')
-rw-r--r--pkg/systemd/generate/pods.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go
index cd1486a82..4043fbfcb 100644
--- a/pkg/systemd/generate/pods.go
+++ b/pkg/systemd/generate/pods.go
@@ -256,6 +256,16 @@ func generatePodInfo(pod *libpod.Pod, options entities.GenerateSystemdOptions) (
return &info, nil
}
+// Unless already specified, the pod's exit policy to "stop".
+func setPodExitPolicy(cmd []string) []string {
+ for _, arg := range cmd {
+ if strings.HasPrefix(arg, "--exit-policy=") || arg == "--exit-policy" {
+ return cmd
+ }
+ }
+ return append(cmd, "--exit-policy=stop")
+}
+
// executePodTemplate executes the pod template on the specified podInfo. Note
// that the podInfo is also post processed and completed, which allows for an
// easier unit testing.
@@ -355,6 +365,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
}
startCommand = append(startCommand, podCreateArgs...)
+ startCommand = setPodExitPolicy(startCommand)
startCommand = escapeSystemdArguments(startCommand)
info.ExecStartPre1 = "/bin/rm -f {{{{.PIDFile}}}} {{{{.PodIDFile}}}}"