Skip to content

Instantly share code, notes, and snippets.

@mil1i
Last active March 3, 2025 06:48
Show Gist options
  • Save mil1i/d7836a56507e89556f8af4f4ee18210b to your computer and use it in GitHub Desktop.
Save mil1i/d7836a56507e89556f8af4f4ee18210b to your computer and use it in GitHub Desktop.
podman-user.service.sh
#!/usr/bin/env bash
sudo mkdir -p /etc/systemd/user/{default.target.wants,timers.target.wants,sockets.target.wants}
sudo mkdir -p /usr/lib/systemd/user
cat <<EOF | sudo tee /etc/systemd/user/sockets.target.wants/podman.socket
[Unit]
Description=Podman API Socket
Documentation=man:podman-system-service(1)
[Socket]
ListenStream=%t/podman/podman.sock
SocketMode=0660
[Install]
WantedBy=sockets.target
EOF
cat <<EOF | sudo tee /etc/systemd/user/timers.target.wants/podman-auto-update.timer
[Unit]
Description=Podman auto-update timer
[Timer]
OnCalendar=daily
RandomizedDelaySec=900
Persistent=true
[Install]
WantedBy=timers.target
EOF
cat <<EOF | sudo tee /etc/systemd/user/default.target.wants/podman-auto-update.service
[Unit]
Description=Podman auto-update service
Documentation=man:podman-auto-update(1)
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/podman auto-update
ExecStartPost=/usr/bin/podman image prune -f
[Install]
WantedBy=default.target
EOF
cat <<EOF | sudo tee /etc/systemd/user/default.target.wants/podman-restart.service
[Unit]
Description=Podman Start All Containers With Restart Policy Set To Always
Documentation=man:podman-start(1)
StartLimitIntervalSec=0
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=true
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING start --all --filter restart-policy=always
ExecStop=/bin/sh -c '/usr/bin/podman $LOGGING stop $(/usr/bin/podman container ls --filter restart-policy=always -q)'
[Install]
WantedBy=default.target
EOF
cat <<EOF | sudo tee /etc/systemd/user/default.target.wants/podman.service
[Unit]
Description=Podman API Service
Requires=podman.socket
After=podman.socket
Documentation=man:podman-system-service(1)
StartLimitIntervalSec=0
[Service]
Delegate=true
Type=exec
KillMode=process
Environment=LOGGING="--log-level=info"
ExecStart=/usr/bin/podman $LOGGING system service
[Install]
WantedBy=default.target
EOF
sudo ln -s /etc/systemd/user/sockets.target.wants/podman.socket /usr/lib/systemd/user/podman.socket
sudo ln -s /etc/systemd/user/timers.target.wants/podman-auto-update.timer /usr/lib/systemd/user/podman-auto-update.timer
sudo ln -s /etc/systemd/user/default.target.wants/podman-auto-update.service /usr/lib/systemd/user/podman-auto-update.service
sudo ln -s /etc/systemd/user/default.target.wants/podman-restart.service /usr/lib/systemd/user/podman-restart.service
sudo ln -s /etc/systemd/user/default.target.wants/podman.service /usr/lib/systemd/user/podman.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment