summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/pods.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-06-15 15:32:43 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-06-15 15:56:02 +0200
commit6118ab494884eea62c388fa1536349f05cdac9d3 (patch)
tree73e90cb653b6512f23d995d05de241932b3d1617 /pkg/systemd/generate/pods.go
parentfe488b5f11836a021bcef6217aeeea41b1321217 (diff)
downloadpodman-6118ab494884eea62c388fa1536349f05cdac9d3.tar.gz
podman-6118ab494884eea62c388fa1536349f05cdac9d3.tar.bz2
podman-6118ab494884eea62c388fa1536349f05cdac9d3.zip
generate systemd: `--replace` on named containers/pods
Use `--replace` for named containers and pods. This will clean up previous containers and podsthat may not have been removed after a system crash. Fixes: #5485 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/systemd/generate/pods.go')
-rw-r--r--pkg/systemd/generate/pods.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go
index 5cfd5ab0a..367b8381f 100644
--- a/pkg/systemd/generate/pods.go
+++ b/pkg/systemd/generate/pods.go
@@ -265,7 +265,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
if podCreateIndex == 0 {
return "", errors.Errorf("pod does not appear to be created via `podman pod create`: %v", info.CreateCommand)
}
- podRootArgs = info.CreateCommand[1 : podCreateIndex-2]
+ podRootArgs = info.CreateCommand[0 : podCreateIndex-2]
podCreateArgs = filterPodFlags(info.CreateCommand[podCreateIndex+1:])
}
// We're hard-coding the first five arguments and append the
@@ -277,6 +277,21 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
"--infra-conmon-pidfile", "{{.PIDFile}}",
"--pod-id-file", "{{.PodIDFile}}"}...)
+ // Presence check for certain flags/options.
+ hasNameParam := false
+ hasReplaceParam := false
+ for _, p := range podCreateArgs {
+ switch p {
+ case "--name":
+ hasNameParam = true
+ case "--replace":
+ hasReplaceParam = true
+ }
+ }
+ if hasNameParam && !hasReplaceParam {
+ podCreateArgs = append(podCreateArgs, "--replace")
+ }
+
startCommand = append(startCommand, podCreateArgs...)
info.ExecStartPre1 = "/usr/bin/rm -f {{.PIDFile}} {{.PodIDFile}}"