Podman Systemd Unit Files
Podman Container kann man mithilfe von systemd units steuern.
Auch Pods und die Abhängigkeiten zwischen Pod und Container lassen sich damit abbilden.
Podman bietet hierfür ein command line utility podman generate systemd an, mit welchem man die komplette Systemd Konfiguration ausgegeben bekommt.
Usage
Pod erstellen, container erstellen
Funktioniert auch mit bereits laufenden Containern
podman pod create --name=my-pod
podman create --pod=my-pod --name=container-a -t centos top
podman create --pod=my-pod --name=container-b -t centos top
Und anschließend Systemd Units generieren, hier bekommen wir für jeden Container und den Pod jeweils ein eigenes.
Die Unitfiles sind mithilfe von BindsTo= und After= so in reihe verdrahtet, dass diese nacheinander starten.
podman generate systemd --new --files --name my-pod
/tmp/pod-my-pod.service
/tmp/container-container-b.service
/tmp/container-container-a.service
Beispiele
pod-my-pod.service
Description=Podman pod-my-pod.service
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=
Requires=container-container-a.service container-container-b.service
Before=container-container-a.service container-container-b.service
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/pod-my-pod.pid %t/pod-my-pod.pod-id
ExecStartPre=/usr/bin/podman pod create --infra-conmon-pidfile %t/pod-my-pod.pid --pod-id-file %t/pod-my-pod.pod-id --name=my-pod --replace
ExecStart=/usr/bin/podman pod start --pod-id-file %t/pod-my-pod.pod-id
ExecStop=/usr/bin/podman pod stop --ignore --pod-id-file %t/pod-my-pod.pod-id -t 10
ExecStopPost=/usr/bin/podman pod rm --ignore -f --pod-id-file %t/pod-my-pod.pod-id
PIDFile=%t/pod-my-pod.pid
Type=forking
[Install]
WantedBy=default.target
container-container-a.service
[Unit]
Description=Podman container-container-a.service
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers
BindsTo=pod-my-pod.service
After=pod-my-pod.service
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/%n.ctr-id
ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --rm --pod-id-file %t/pod-my-pod.pod-id --sdnotify=conmon -d --replace --name=container-a -t centos top
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
[Install]
WantedBy=default.target
Links
Weitere Infos zu dem Thema: https://www.redhat.com/sysadmin/podman-run-pods-systemd-services