Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with podman generate systemd #5485

Closed
larsks opened this issue Mar 12, 2020 · 11 comments · Fixed by #6553
Closed

Problems with podman generate systemd #5485

larsks opened this issue Mar 12, 2020 · 11 comments · Fixed by #6553
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@larsks
Copy link
Contributor

larsks commented Mar 12, 2020

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

The unit files produced by podman generate systemd --new ... are problematic because they will fail to start the service if the system crashes. This happens because the container is only removed as part of ExecStopPost, and during a crash (/power failure/etc) that never runs. The result is that a subsequent attempt to start the service will fail with Error: error creating container storage: the container name "your_container_name" is already in use by ....

You can't simply drop the --new, because then the resulting unit file won't actually create the container if it doesn't exist.

What you really need to make this robust is one of two things:

  • Tie the lifetime of the container to the lifetime of the podman command. When the podman exits, the container is gone. This would make a containerized service behave like a normal un-containerized service, which would work well with a process manager like systemd.

  • Allow replacing an existing container with a new container. E.g., introduce a --replace flag to podman run so that podman run --replace --name foo ... would permit create a new container named foo even if one already exists.

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 12, 2020
@mheon
Copy link
Member

mheon commented Mar 12, 2020

@vrothberg PTAL

@vrothberg
Copy link
Member

vrothberg commented Mar 13, 2020

Thanks for reaching out, @larsks !

I like the idea of a --replace flag as it allows to generalize this problem beyond systemd.

@mheon @giuseppe @rhatdan WDYT?

@giuseppe
Copy link
Member

could we add a ExecStartPre that does a rm -f?

@vrothberg
Copy link
Member

could we add a ExecStartPre that does a rm -f?

That will only work for containers that have been named but won't work for unnamed containers.

@mheon
Copy link
Member

mheon commented Mar 13, 2020 via email

@github-actions
Copy link

A friendly reminder that this issue had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Apr 13, 2020

@larsks @vrothberg Does this issue still exist?

@vrothberg
Copy link
Member

Yes. The idea is to add --replace to run/create which will remove an existing container in case of a name conflict. There are a couple of issues I want to tackle once the v2 work is closer to the finish line.

@rhatdan
Copy link
Member

rhatdan commented Jun 9, 2020

@vrothberg Any progress on this?

@vrothberg
Copy link
Member

Thanks for the ping. No progress yet but I'll tackle it now.

vrothberg added a commit to vrothberg/libpod that referenced this issue Jun 15, 2020
Add a `--replace` flag to the `container {create,run}` commands.
If another container with the same name already exists, it will
be replaced and removed.

Adding this flag is motivated by containers#5485 to make running Podman in systemd
units (or any other scripts/automation) more robust.  In case of a
crash, a container may not be removed by a sytemd unit anymore.  The
`--replace` flag allows for supporting crashes.

Signed-off-by: Valentin Rothberg <[email protected]>
vrothberg added a commit to vrothberg/libpod that referenced this issue Jun 15, 2020
Add a `--replace` flag to the `pod create` command.  If another pod with
the same name already exists, it will be replaced and removed.

Adding this flag is motivated by containers#5485 to make running Podman in systemd
units (or any other scripts/automation) more robust.  In case of a
crash, a pod may not be removed by a sytemd unit anymore.  The
`--replace` flag allows for supporting crashes.

Note that the `--replace` flag does not require the `--name` flag to be
set, so it can be set unconditionally in `podman generate systemd`.

Signed-off-by: Valentin Rothberg <[email protected]>
vrothberg added a commit to vrothberg/libpod that referenced this issue Jun 15, 2020
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: containers#5485
Signed-off-by: Valentin Rothberg <[email protected]>
@vrothberg
Copy link
Member

#6553 will fix it 👍

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants