Skip to content

Instantly share code, notes, and snippets.

@queeup
Created February 14, 2022 18:50
Show Gist options
  • Save queeup/3c20a913e0b3ef7983d846d4c68515c0 to your computer and use it in GitHub Desktop.
Save queeup/3c20a913e0b3ef7983d846d4c68515c0 to your computer and use it in GitHub Desktop.
Dynamic container systemd service
# Dynamic container systemd service
# Files:
# ~/.config/systemd/user/[email protected]
# ~/.config/container@<name of container>.conf
# Usage:
# command: systemctl --user start container@<name of container>
# config: container@<name of container>.conf
[Unit]
Description=Podman %n
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=%h/.config/%N.conf
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/%n.ctr-id
ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --sdnotify=conmon \
--label "io.containers.autoupdate=registry" \
--rm \
--replace \
--detach \
--name %i \
--hostname %i \
$PODMAN_RUN_ARGS \
$ENV \
$VOLUMES \
$PUBLISH \
$IMAGE \
$COMMAND
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=multi-user.target default.target
# use this env except [--rm, --replace, --detach, --name, --hostname]
PODMAN_RUN_ARGS=
ENV=--env PUID=1000 \
--env PGID=1000 \
--env TZ=Europe/London \
PUBLISH=--publish 8384:8384 \
--publish 22000:22000/tcp \
--publish 22000:22000/udp \
--publish 21027:21027/udp \
VOLUMES=--volume syncthing_data:/config
IMAGE=lscr.io/linuxserver/syncthing
COMMAND=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment