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

Restart Policy not set #91

Open
bilalbinameer opened this issue Nov 25, 2019 · 25 comments
Open

Restart Policy not set #91

bilalbinameer opened this issue Nov 25, 2019 · 25 comments

Comments

@bilalbinameer
Copy link

when I use podman-compose to up my pods, restart policy is not set, while in docker-compose it sets restart policy.
Output of docker inspect (Up by docker-compose)
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
while there is no key RestartPolicy when up by podman-compose in podman inspect

@muayyad-alsadi
Copy link
Collaborator

Ok. I'll try to do that this week end

@DesSolo
Copy link

DesSolo commented Jan 29, 2020

@muayyad-alsadi Any news?)

@bilal-ameer-ivolve
Copy link

@DesSolo
Podman do not have any restart policy.
you have to write a systemd script for it.

@mheon
Copy link
Member

mheon commented Jan 30, 2020

Not true, Podman has included restart policies for some time (I think we added it in the 1.4.x releases?)

@bilal-ameer-ivolve
Copy link

@mheon
I don't know exactly if restart policy is here in 1.4.x release. I'll check it and post here.
But currently I am using "podman generate systemd" to specify restart policy.

@kiview
Copy link

kiview commented Mar 4, 2020

@muayyad-alsadi
You need any help with that? Would this be a good issue to start getting involved with podman-compose?

@tooxo
Copy link

tooxo commented Mar 28, 2020

Any updates on this? Is this still worked on?

@zx1986
Copy link

zx1986 commented Jul 22, 2020

Does "restart: always" work well with podman-compose now?

@xamadev
Copy link

xamadev commented Oct 19, 2020

Does "restart: always" work well with podman-compose now?

Any update?

@muayyad-alsadi
Copy link
Collaborator

muayyad-alsadi commented Oct 19, 2020

this seems to be fixed here, but it's podman not respecting as @bilal-ameer-ivolve mensioned

047820d

@paulkitt
Copy link

Any news on this? Would be great :)

@rjuju
Copy link

rjuju commented Nov 11, 2021

For the record I ran into this issue too. After switching from v0.1.5 to devel@HEAD the restart policy works as intended.

Do you have any plan to release another v0.x version?

@EzeKoren
Copy link

EzeKoren commented Mar 2, 2022

Running podman-compose version 1.0.3 from pypi I still have this issue. in a docker-compose.yml file, the flag restart: unless-stopped doesn't cause the container to start after a reboot, and neither does restart: always

@muayyad-alsadi
Copy link
Collaborator

@EzeKoren here is a buysbox docker-compose and the output podman-compose up -d

services:
    web:
      image: busybox
      command: ["/bin/busybox", "httpd", "-f", "-h", "/var/www/html", "-p", "8000"]
      restart: always
podman run ... --restart always ... busybox /bin/busybox httpd -f -h /var/www/html -p 8000

as you can see it's passed

would you please share the output from your side (do down and up)

@EzeKoren
Copy link

EzeKoren commented Mar 3, 2022

@muayyad-alsadi thank you for your reply. The container passed and it's executed normally after running podman-composed up. After a reboot, the containers still exist but they're not started automatically as instructed by the flag, sorry if the previous comment was not clear.

I did manage to work around this issue by creating a systemd service using podman generate systemd --name container-name --files --new (NOTE: this command must be run as sudo if it references a container in rootful mode), and then enabling and restarting said service.

It could be useful to either implement this functionality on podman-compose itself or at least document this workaround

@muayyad-alsadi
Copy link
Collaborator

this is quoted from podman manual page

   --restart=policy
       Restart policy to follow when containers exit.  Restart policy will not take effect if a container is stopped via the podman kill or podman stop commands.

       Valid policy values are:

              • no                       : Do not restart containers on exit

              • on-failure[:max_retries] : Restart containers when they exit with a non-zero exit code, retrying indefinitely or until the optional max_retries count is hit

              • always                   : Restart containers when they exit, regardless of status, retrying indefinitely

              • unless-stopped           : Identical to always

       Please note that restart will not restart containers after a system reboot.  If this functionality is required in your environment, you can invoke Podman from a systemd.unit(5) file, or create an  init  script  for  whichever
       init system is in use.  To generate systemd unit files, please see podman generate systemd.

It could be useful to either implement this functionality on podman-compose itself or at least document this workaround

I'm working on integrating podman-compose with systemd
there are some discussion about this.
I'm currently considering a unit with something like

ExecStartPre=/bin/podman-compose up --no-start
ExecStartPre=/bin/podman pod start pod_mypod
ExecStart=/bin/podman pod wait cnt1 cnt2 ...

@WittyNameHere
Copy link

WittyNameHere commented Jul 19, 2022

I'm relatively new to containers, Linux, etc. But from what I can see, podman-compose creates a pod for all the containers in the .yaml file and adds them to that pod. You can get the pod ID from podman pod ps then use podman generate systemd --new on the pod ID to generate a systemd definition for that pod that will behave like compose does, destroying and taking down the pod and it's containers whenever stopped. The problem is, that definition includes a full podman run line for the containers in the compose file, and won't change whenever the YAML file is changed.

A solution I can think of would be for podman-compose to detect a restart: policy in the services part of a compose file, and when needed create/enable a systemd serivce for the pod and relevant apps in the correct place (~/.config/systemd/user/ for rootless containers, /etc/systemd/system/ for rootful ones) to persist through a system reboot, and then delete that service file on podman-compose down. However, persistance for rootless containers will also require user session lingering to be enabled to start the pod and containers on reboot and accomplish what Docker does with the daemon. Ideally the user would learn how to enable lingering if necessary when trying to run something rootless with a restart policy such as always or unless-stopped.

@Alwaysin
Copy link

We definetly need a podman-compose generate systemd just as we have podman generate systemd or a compliance of the restart: always/unless-stoped in this scenario!

@interj
Copy link

interj commented Feb 7, 2023

Podman-compose seems to respect the restart policy, but the podman doesn't - I needed to enable the service that is not enabled by default:
systemctl --user enable podman-restart
containers/podman#10539

@yingshaoxo
Copy link

I have a simpler solution, just use sudo apt install docker-compose, it will install docker and docker-compose all togather.

So, there has no need to install other stuff.

@stephenpmurray
Copy link

Just for reference, this appears to be working fine for me, running:
podman-compose version 1.0.6
podman version 4.5.1
on Fedora 38

@Jack12816
Copy link

@stephenpmurray I cannot this fully.

$ podman-compose -v

podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.4.1
podman-compose version 1.0.6
podman --version
podman version 4.4.1
exit code: 0

Works

services:
  app:
    restart: on-failure      

Passed down to the podman create call as --restart on-failure.

Doesn't Work

services:
  app:
    deploy:
      restart_policy:
        condition: on-failure  

Not passed down to the podman create call.

@stephenpmurray
Copy link

stephenpmurray commented Jul 3, 2023

@Jack12816 Sorry it looks like I misunderstood what was being discussed in the thread. Yes,

services:
  app:
    restart: ...

was working for me

Apologies for any confusion

@meyca
Copy link

meyca commented Sep 9, 2023

I suggest closing this. On Debian 12.1 with

~ $ podman-compose version
['podman', '--version', '']
using podman version: 4.3.1
podman-composer version  1.0.3
podman --version 
podman version 4.3.1
exit code: 0

containers with "restart: always" in docker-compose.yml will be restarted on reboot through

$ systemctl status podman-restart.service 

● podman-restart.service - Podman Start All Containers With Restart Policy Set To Always
     Loaded: loaded (/lib/systemd/system/podman-restart.service; enabled; preset: enabled)
     Active: active (exited) since Sat 2023-09-09 14:10:11 CEST; 6min ago
       Docs: man:podman-start(1)
    Process: 1623 ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always (code=exited, status=0/SUCCESS)
   Main PID: 1623 (code=exited, status=0/SUCCESS)
      Tasks: 10 (limit: 76833)
     Memory: 18.4M
        CPU: 1.630s
     CGroup: /system.slice/podman-restart.service

@jason-smith80
Copy link

jason-smith80 commented May 18, 2024

Using Ubuntu 24.04, I have enabled:

user:~$ systemctl --user enable podman-restart

and marked each of my containers in the compose.yml file with:

services:
   foo:
      ...
      restart: always

   bar:
      ...
      restart: always

Starting up the containers as a regular (non-sudo) user works fine:

user:~$ podman-compose up -d

And the restart service is running:

user:~$ systemctl status podman-restart
● podman-restart.service - Podman Start All Containers With Restart Policy Set To Always
     Loaded: loaded (/usr/lib/systemd/system/podman-restart.service; enabled; preset: enabled)
     Active: active (exited) since Sat 2024-05-18 12:58:26 CEST; 13min ago
       Docs: man:podman-start(1)
    Process: 717 ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always (code=exited, status=0/SUCCESS)
   Main PID: 717 (code=exited, status=0/SUCCESS)
        CPU: 46ms

Warning: some journal files were not opened due to insufficient permissions.

After rebooting the system, the containers do not come up automatically. However, when I manually ssh into the user account, the containers are started immediately.

I also tried this:

user:~ $ sudo systemctl enable podman-restart

(so without the --user flag), but that does not work either.

That is workable for manual upgrades/maintenance, but is obviously not helpful to recover from power failures etc. Does restart not work for sudo-less regular user accounts?


Edit: I learned that the following will open a user session after reboot:

user:~ $ sudo loginctl enable-linger user

The above command fixed my problem. Rebooting the server will automatically spin up the containers under my regular user account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests