diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-06-15 12:54:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 12:54:36 -0400 |
commit | 10c6c806ea6d7830c248d9c89cd5ec3a7a515a63 (patch) | |
tree | 837474da079889daa027b66e5239915dd983f7ab /pkg/systemd/generate/containers.go | |
parent | b89729778c253f0eccd2dd762e5d0a6547aaea7d (diff) | |
parent | 6118ab494884eea62c388fa1536349f05cdac9d3 (diff) | |
download | podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.tar.gz podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.tar.bz2 podman-10c6c806ea6d7830c248d9c89cd5ec3a7a515a63.zip |
Merge pull request #6553 from vrothberg/replace
--replace for containers and pods
Diffstat (limited to 'pkg/systemd/generate/containers.go')
-rw-r--r-- | pkg/systemd/generate/containers.go | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index dced1a3da..4180022cb 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -207,24 +207,42 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst info.CreateCommand = filterPodFlags(info.CreateCommand) } - // Enforce detaching - // - // since we use systemd `Type=forking` service - // @see https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= - // when we generated systemd service file with the --new param, - // `ExecStart` will have `/usr/bin/podman run ...` - // if `info.CreateCommand` has no `-d` or `--detach` param, - // podman will run the container in default attached mode, - // as a result, `systemd start` will wait the `podman run` command exit until failed with timeout error. + // Presence check for certain flags/options. hasDetachParam := false + hasNameParam := false + hasReplaceParam := false for _, p := range info.CreateCommand[index:] { - if p == "--detach" || p == "-d" { + switch p { + case "--detach", "-d": hasDetachParam = true + case "--name": + hasNameParam = true + case "--replace": + hasReplaceParam = true } } + if !hasDetachParam { + // Enforce detaching + // + // since we use systemd `Type=forking` service @see + // https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= + // when we generated systemd service file with the + // --new param, `ExecStart` will have `/usr/bin/podman + // run ...` if `info.CreateCommand` has no `-d` or + // `--detach` param, podman will run the container in + // default attached mode, as a result, `systemd start` + // will wait the `podman run` command exit until failed + // with timeout error. startCommand = append(startCommand, "-d") } + if hasNameParam && !hasReplaceParam { + // Enforce --replace for named containers. This will + // make systemd units more robuts as it allows them to + // start after system crashes (see + // github.com/containers/libpod/issues/5485). + startCommand = append(startCommand, "--replace") + } startCommand = append(startCommand, info.CreateCommand[index:]...) info.ExecStartPre = "/usr/bin/rm -f {{.PIDFile}} {{.ContainerIDFile}}" |