podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Podman Compose Systemd registers an unusable service

Open tiberez opened this issue 2 years ago • 5 comments

While trying to run a podman-compose containing two containers of wireguard and wireguard-ui on my raspberry pi, I went into configuring the restart policy which impies:

  • Creating a unit file:
➜  wireguard-ui sudo podman-compose systemd --action create-unit
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.6.1
writing [/etc/systemd/user/[email protected]]: ...
writing [/etc/systemd/user/[email protected]]: done.

while in your project type `podman-compose systemd -a register`
  • Registering a service file
➜  wireguard-ui podman-compose systemd -a register
podman-compose version: 1.0.6
['podman', '--version', '']
using podman version: 4.6.1
writing [/home/t/.config/containers/compose/projects/wireguard-ui.env]: ...
writing [/home/t/.config/containers/compose/projects/wireguard-ui.env]: done.


creating the pod without starting it: ...
.
.
.

final exit code is  0

you can use systemd commands like enable, start, stop, status, cat
all without `sudo` like this:

                systemctl --user enable --now 'podman-compose@wireguard-ui'
                systemctl --user status 'podman-compose@wireguard-ui'
                journalctl --user -xeu 'podman-compose@wireguard-ui'

and for that to work outside a session
you might need to run the following command *once*

                sudo loginctl enable-linger 'tib'

you can use podman commands like:

                podman pod ps
                podman pod stats 'pod_wireguard-ui'
                podman pod logs --tail=10 -f 'pod_wireguard-ui'

The problem is that the service will not start, neither on reboot nor manually:

wireguard-ui systemctl --user start [email protected]  
Job for [email protected] failed because the control process exited with error code.
See "systemctl --user status [email protected]" and "journalctl --user -xeu [email protected]" for details.

➜  wireguard-ui systemctl --user status 'podman-compose@wireguard-ui'
× [email protected] - wireguard-ui rootless pod (podman-compose)
     Loaded: loaded (/etc/xdg/systemd/user/[email protected]; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-08-26 22:30:06 CEST; 7min ago
    Process: 1595 ExecStartPre=/usr/bin/podman-compose up --no-start (code=exited, status=0/SUCCESS)
    Process: 1726 ExecStartPre=/usr/bin/podman pod start pod_wireguard-ui (code=exited, status=125)
    Process: 1736 ExecStopPost=/usr/bin/podman-compose down (code=exited, status=0/SUCCESS)
        CPU: 3.845s

Aug 26 22:30:05 tib-archpi podman[1773]: 2023-08-26 22:30:05.522401386 +0200 CEST m=+0.248127112 container remove 98b41b6226f4262936359291863f4c44275de5a8273d6b37754245240e31d44e (image=docker.io/ngoduykhanh/wireguard-ui:latest, name=>
Aug 26 22:30:05 tib-archpi podman-compose[1773]: wireguard-ui
Aug 26 22:30:05 tib-archpi podman-compose[1736]: exit code: 0
Aug 26 22:30:05 tib-archpi podman-compose[1736]: podman rm wireguard
Aug 26 22:30:06 tib-archpi podman[1785]: 2023-08-26 22:30:06.239692904 +0200 CEST m=+0.691045167 container remove 519f6f6ac02efd8a0c1723890439e91a2ff1c0829b536df3337109467ff5906d (image=lscr.io/linuxserver/wireguard:latest, name=wireg>
Aug 26 22:30:06 tib-archpi podman-compose[1785]: wireguard
Aug 26 22:30:06 tib-archpi podman-compose[1736]: exit code: 0
Aug 26Warning: The unit file, source configuration file or drop-ins of [email protected] changed on disk. Run 'systemctl --user daemon-reload' to reload units.
 22:30:06 tib-archpi systemd[1581]: [email protected]: Failed with result 'exit-code'.
Aug 26 22:30:06 tib-archpi systemd[1581]: Failed to start wireguard-ui rootless pod (podman-compose).
Aug 26 22:30:06 tib-archpi systemd[1581]: [email protected]: Consumed 3.845s CPU time.
...skipping...
× [email protected] - wireguard-ui rootless pod (podman-compose)
     Loaded: loaded (/etc/xdg/systemd/user/[email protected]; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sat 2023-08-26 22:30:06 CEST; 7min ago
    Process: 1595 ExecStartPre=/usr/bin/podman-compose up --no-start (code=exited, status=0/SUCCESS)
    Process: 1726 ExecStartPre=/usr/bin/podman pod start pod_wireguard-ui (code=exited, status=125)
    Process: 1736 ExecStopPost=/usr/bin/podman-compose down (code=exited, status=0/SUCCESS)
        CPU: 3.845s

Aug 26 22:30:05 tib-archpi podman[1773]: 2023-08-26 22:30:05.522401386 +0200 CEST m=+0.248127112 container remove 98b41b6226f4262936359291863f4c44275de5a8273d6b37754245240e31d44e (image=docker.io/ngoduykhanh/wireguard-ui:latest, name=>
Aug 26 22:30:05 tib-archpi podman-compose[1773]: wireguard-ui
Aug 26 22:30:05 tib-archpi podman-compose[1736]: exit code: 0
Aug 26 22:30:05 tib-archpi podman-compose[1736]: podman rm wireguard
Aug 26 22:30:06 tib-archpi podman[1785]: 2023-08-26 22:30:06.239692904 +0200 CEST m=+0.691045167 container remove 519f6f6ac02efd8a0c1723890439e91a2ff1c0829b536df3337109467ff5906d (image=lscr.io/linuxserver/wireguard:latest, name=wireg>
Aug 26 22:30:06 tib-archpi podman-compose[1785]: wireguard
Aug 26 22:30:06 tib-archpi podman-compose[1736]: exit code: 0
Aug 26Warning: The unit file, source configuration file or drop-ins of [email protected] changed on disk. Run 'systemctl --user daemon-reload' to reload units.
 22:30:06 tib-archpi systemd[1581]: [email protected]: Failed with result 'exit-code'.
Aug 26 22:30:06 tib-archpi systemd[1581]: Failed to start wireguard-ui rootless pod (podman-compose).
Aug 26 22:30:06 tib-archpi systemd[1581]: [email protected]: Consumed 3.845s CPU time.

A more in depth log analisys shows a container with the same name is already existing, even if I did not manually started the compose file:

wireguard-ui journalctl --user -xeu [email protected]
Aug 26 22:52:23 tib-archpi podman-compose[3130]: podman-compose version: 1.0.6
Aug 26 22:52:23 tib-archpi podman-compose[3130]: ['podman', '--version', '']
Aug 26 22:52:23 tib-archpi podman-compose[3130]: using podman version: 4.6.1
Aug 26 22:52:23 tib-archpi podman-compose[3130]: ** excluding:  set()
Aug 26 22:52:23 tib-archpi podman-compose[3130]: ['podman', 'ps', '--filter', 'label=io.podman.compose.project=wireguard-ui', '-a', '--format', '{{ index .Labels "io.podman.compose.config-hash"}}']
Aug 26 22:52:23 tib-archpi podman-compose[3130]: ['podman', 'network', 'exists', 'wireguard-ui_default']
Aug 26 22:52:23 tib-archpi podman-compose[3130]: podman create --name=wireguard --label io.podman.compose.config-hash=508772c49574768860409fbcf846579df714f7c00037e4a6f0e3640d98072dfc --label io.podman.compose.project=wireguard-ui --la>
Aug 26 22:52:23 tib-archpi podman[3157]: 2023-08-26 22:52:23.84373802 +0200 CEST m=+0.081732854 image pull 6d14a9c37b08eb96533d35645b783da669e5c0c4a98ab843e944ed94073621cf lscr.io/linuxserver/wireguard:latest
Aug 26 22:52:24 tib-archpi podman-compose[3157]: Error: creating container storage: the container name "wireguard" is already in use by 67741204d7cf2585d798c21ca939183580d895c64fefc5cebf0557e61d2be38d. You have to remove that containe>
Aug 26 22:52:24 tib-archpi podman-compose[3130]: exit code: 125
Aug 26 22:52:25 tib-archpi podman-compose[3130]: podman create --name=wireguard-ui --requires=wireguard --label io.podman.compose.config-hash=508772c49574768860409fbcf846579df714f7c00037e4a6f0e3640d98072dfc --label io.podman.compose.p>
Aug 26 22:52:25 tib-archpi podman[3166]: 2023-08-26 22:52:25.58253708 +0200 CEST m=+0.088510974 image pull 29720b04d40cb6cd64c69514d2f2aeb0b0b1c6e1ad5346133e5db5d81104dcec ngoduykhanh/wireguard-ui:latest
Aug 26 22:52:25 tib-archpi podman-compose[3166]: Error: creating container storage: the container name "wireguard-ui" is already in use by 18a5fcbeacb356262bee6759710877f438e92a43a91d3597b366fd1732747e09. You have to remove that conta>
Aug 26 22:52:25 tib-archpi podman-compose[3130]: exit code: 125
Aug 26 22:52:26 tib-archpi podman[3176]: Error: no pod with name or ID pod_wireguard-ui found: no such pod
Aug 26 22:52:26 tib-archpi systemd[1574]: [email protected]: Control process exited, code=exited, status=125/n/a

So I checked the linked systemd file:

# /etc/systemd/user/[email protected]

[Unit]
Description=%i rootless pod (podman-compose)

[Service]
Type=simple
EnvironmentFile=%h/.config/containers/compose/projects/%i.env
ExecStartPre=-/usr/bin/podman-compose up --no-start    <--- conteiners created here
ExecStartPre=/usr/bin/podman pod start pod_%i                <--- Start and probaly fail here
ExecStart=/usr/bin/podman-compose wait
ExecStop=/usr/bin/podman pod stop pod_%i

[Install]
WantedBy=default.target

I see that containers are generated and started on separated instances, what I've done is creating and starting the up command:

# /etc/systemd/user/[email protected]

[Unit]
Description=%i rootless pod (podman-compose)

[Service]
Type=simple
EnvironmentFile=%h/.config/containers/compose/projects/%i.env
ExecStartPre=-/usr/bin/podman-compose up -d
ExecStart=/usr/bin/podman-compose wait
ExecStop=/usr/bin/podman pod stop pod_%i

[Install]
WantedBy=default.target

This solved my issues, still this should work out of the box. Am I doing something wrong? Cheers

Environment:

  • OS: Linux (Arch)
  • podman version: 4.6.1
  • podman compose version: (git hex) 1.0.6

tiberez avatar Aug 26 '23 22:08 tiberez

Problem is that the systemd unit file assumes that podman-compose up defaults to creating a pod, which it possibly did on a previous version? Need to add --in-pod=1 to this line, I'll create a pull request.

PointyShinyBurning avatar Sep 13 '23 13:09 PointyShinyBurning

Lol, please ignore the two broken pull-requests, my brain is clearly on the fritz this afternoon.

PointyShinyBurning avatar Sep 13 '23 13:09 PointyShinyBurning

this should be fixed by merging #772

maurerle avatar Oct 04 '23 05:10 maurerle

there is no need for #772 because in latest dev in-pod defaults to 1

actually pod-systemd was never part of previous stable, and in-pod is a breaking change that's why it's disabled in latest stable

you have two options

  • use current stable with podman per-container systemd units ( podman generate systemd CNT)
  • use latest devel branch with in-pod

muayyad-alsadi avatar Oct 05 '23 07:10 muayyad-alsadi

I just wanted to post a workaround for people using the stable version. You can create a drop-in systemd file with modified ExecStartPre commands like this:

  1. Execute systemctl --user edit [email protected]
  2. Below line saying "Anything between here…" insert these lines:
    [Service]
    ExecStartPre=
    ExecStartPre=-/usr/bin/podman-compose --in-pod=1 up --no-start
    ExecStartPre=/usr/bin/podman pod start pod_%i
    

nawordar avatar Dec 21 '23 07:12 nawordar