How to setup podman with systemd, if same container is to be run each time?
(i.e. not podman run --replace
)
Get pidfile from podman inspect:
cd ~/
# container-mypodmancontainer.service must be re-generated if container-id changes
# prerequisite: podman container mypodmancontainer exists
mkdir -vp ~/.config/systemd/user/
cat > ~/.config/systemd/user/container-mypodmancontainer.service <<EOT
[Unit]
Description=Podman container-mypodmancontainer.service
Documentation=mydocs
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=always
TimeoutStopSec=70
ExecStart=/usr/bin/podman start mypodmancontainer
ExecStop=/usr/bin/podman stop -t 5 mypodmancontainer
Type=forking
PIDFile=$(podman inspect --format '{{ .PidFile }}' mypodmancontainer)
[Install]
WantedBy=default.target
EOT
systemctl --user daemon-reload