Open pinko-fowle opened 9 months ago
I think the problem here is differentiating between whether the container was actually stopped.
@vrothberg Do you know about this?
Needs investigation. The podman-restart.service
only stops containers with restart=always on shutdown but there may still be something else at play.
Ah, yes. The restart service only starts containers with --restart=always
.
Does Docker differentiate ones that we shutdown via Human versus shutdown because the system was rebooting. We might need to somehow figure this out. I would figure restart "unless-stopped" containers should start on reboot, if they we shut down via reboot, as opposed to someone doing a podman stop. (Of course I am not sure Podman knows the difference since systemd is trigging podman stops.
A friendly reminder that this issue had no activity for 30 days.
For those who are looking for a fix, run
systemctl --user edit podman-restart.service
And add
[Service]
ExecStart=
ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always --filter restart-policy=unless-stopped
ExecStop=
ExecStop=/bin/sh -c '/usr/bin/podman $LOGGING stop $(/usr/bin/podman container ls --filter restart-policy=always --filter restart-policy=unless-stopped -q)'
Save, then run
systemctl --user enable podman-restart.service
A friendly reminder that this issue had no activity for 30 days.
I regret to inform that this glaring error has yet to be rectified.
Hi there, could it be that restart-policy
as filter is not documented? Also is there a reason to use /bin/sh
during ExceStop
but not during ExceStart
?
@jennydaman How does your override work? if you call podman stop during service stop doesn't that mean that it wouldn't start the next time because it was stopped?
@apollo13 it is only necessary to use /bin/sh
during ExecStop
because we need a subshell. ExecStart
does not involve a subshell.
I assume by "the next time" you mean on reboot. Containers are going to be started the next reboot, because booting starts podman-restart.service
which starts all containers with restart-policy=always
or restart-policy=unless-stopped
.
@apollo13 it is only necessary to use
/bin/sh
duringExecStop
because we need a subshell.ExecStart
does not involve a subshell.
But why? It seems as podman stop --all --filter restart-policy=always --filter restart-policy=unless-stopped
should work as well.
I assume by "the next time" you mean on reboot. Containers are going to be started the next reboot, because booting starts
podman-restart.service
which starts all containers withrestart-policy=always
orrestart-policy=unless-stopped
.
Yes, I ment on reboot. But this seems wrong to me. Consider:
podman run --name=test --rm -it --restart=unless-stopped fedora:latest
podman stop test
reboot
Now test container will be restarted even though it is explicitly stopped.
EDIT:// I see that this was pointed out at https://github.com/containers/podman/pull/20962#issuecomment-1849018913 already
Yes this is something we need to fix, although I am not sure if we can differentiate between podman stop and systemctl stop, which could trigger a podman stop on reboot.
I think we can't currently. What about a flag for podman stop
ala --from-service-manager
or an environment variable which signals that it is called from systems? Then podman could save that information somewhere.
On Mon, Feb 5, 2024, at 21:44, Daniel J Walsh wrote:
Yes this is something we need to fix, although I am not sure if we can differentiate between podman stop and systemctl stop, which could trigger a podman stop on reboot.
— Reply to this email directly, view it on GitHub https://github.com/containers/podman/issues/20418#issuecomment-1928062059, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAT5C5XJX46SIQHCWY7SHTYSFABBAVCNFSM6AAAAAA6HYNT6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRYGA3DEMBVHE. You are receiving this because you were mentioned.Message ID: @.***>
Issue Description
Containers with
RestartPolicy=unless-stopped
are never started.Steps to reproduce the issue
Describe the results you received
All containers with the "unless-stopped" configuration are not restarted by podman-restart.service.
Describe the results you expected
All running containers with a "unless-stopped" configuration get restarted by podman-restart.service upon system boot.
podman info output
Podman in a container
No
Privileged Or Rootless
Privileged
Upstream Latest Release
Yes
Additional environment details
Running on MacOS via homebrew.
Additional information
17851 and #17580 have also reported this & been closed, but this is still happening.
This is quite painful, because
always
containers are always restarted. Many devs in my org will have multiple copies of, for example, a postgres database container. We expect to be able to stop most of them, but have one started, and have that one and only that one resume when podman machine starts up after reboot.But currently, with
podman-restart
, allalways
containers will start, and the multiple postgres containers will all try to grab the same 5432 port.There were some asks in #10539 about how to implement
unless-stopped
, but no answers were found there. It seems like we need to store more state than we have available (or than I know how to access) to properly implement this capability: we have to know what containers were running, which were stopped, as podman shuts down/system reboots.