Auto start pods in fedora

Greetings
I have deployed an open-source ERP called ERPnext. I have created a new pod with several containers that depend on each other. Now, I can start the pod using podman pod start mypod, which works perfectly.

But, I want to automate the start of the pod when the host starts, therefore, I created a simple .service file with the following content

[Unit]
Description=My custom service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/podman pod stats pod_mypod
Restart=on-failure

[Install]
WantedBy=multi-user.target

First, I put the .service file in /etc/systemd/system and I got the following error:
Jan 08 18:28:41 fedora podman[71968]: Error: no pod with name or ID pod_mypod found: no such pod
and then I created another .service file with the same content inside ~/.config/systemd/user but in this case there is no error, but it recurrsevely outputs status of each containers with 0% CPU and RAM usage and it doesn’t start the pod.
Is there an easy way to automate starting of pods?
Thank you.

1 Like

Your pod is started by your user.
The .service file does not run as your user so it does not see the pod.

I believe you can specify the user to use when launching that command within the .service file.
Something like User=<username> as a line within the [Service] section may be a start

Thanks but I have already tested with putting the service file under ~/.config/systemd/user which makes the service to be executed by non administrator user

Hello @elhanan and welcome to :fedora: !

You can check out Podman Quadlet, namely Pod units, if you haven’t already.

1 Like

Ok thank you, I will read about that now, I checked out a package called podlet and it seems good.

Hello @hricky I have just read podman-systemd.unit — Podman documentation

I already have a running pod containing 5-6 containers. Is it possible to generate a system daemon from running pods? I couldn’t see any examples of that.

I haven’t used it, but it looks like the tool you mentioned (GitHub - containers/podlet: Generate Podman Quadlet files from a Podman command, compose file, or existing object) might be suitable for a similar purpose. I personally prefer to write the Quadlet files myself, as it gives me more control and flexibility. You can at least try Podlet and use the generated files as a starting point.

1 Like

Yeah, Unfortunately, that tool has not getting an update recently and there is an issue generating Quadlet from the existing pod, using podlet generate pod pod_mypod

Error: 
   0: error creating Quadlet file(s) from an existing object
   1: error parsing `podman pod create` command from `["podman", "pod", "create", "--name=pod_mypod", "--infra=false", "--share="]`
   2: error: unexpected argument '--name' found

        tip: to pass '--name' as a value, use '-- --name'

   2: Usage: create [OPTIONS] <NAME>

      For more information, try '--help'.
   2: 

Location:
   src/cli/generate.rs:277

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Can you please suggest any articles with examples on Quadlet?

If you haven’t read them yet, I would suggest a short article and a much longer but comprehensive official documentation with lots of examples.

1 Like

Ok, I will check on them, thank you

Amazingly I couldn’t find the use case I am looking for on both articles, the examples only focus on creating systemd files for a single container, it doesn’t even mention pod unit files.
I am going to search for good examples again.

Since containers are ephemeral in nature, I don’t quite get why you wouldn’t just remove the containers and the pod and then simply create a Quadlet, but maybe you have a reason not to.

Anyhow, in the 14.7. Automatically starting pods using systemd section in the docs that I gave you a link to in my previous post, it is described how you can start multiple containers managed by the systemd pod service. As you already have running containers in a pod, you can skip steps 1 through 4. Here is the link to the deprecated podman generate systemd command in the Podman docs.