Skip to content

Instantly share code, notes, and snippets.

@izzyleung
Last active December 19, 2025 00:29
Show Gist options
  • Select an option

  • Save izzyleung/ff5ec810fcd0f3a741748268887fb1fe to your computer and use it in GitHub Desktop.

Select an option

Save izzyleung/ff5ec810fcd0f3a741748268887fb1fe to your computer and use it in GitHub Desktop.
Manage Homebridge as a SystemD service via Podman

New way

If the version of podman installed in your system supports podlet (a.k.a >= 4.4.0), you should consider using podlet generators to help you generate SystemD unit files.

You should create a file named homebridge.container under $HOME/.config/containers/systemd:

[Unit]
Description=Homebridge Service

[Service]
Restart=always

[Install]
WantedBy=default.target

[Container]
Image=docker.io/homebridge/homebridge:latest
AutoUpdate=registry
ContainerName=homebridge
Network=host
Environment=TZ=America/Los_Angeles # Update with your timezone
Volume=%h/.containers/volumes/homebridge:/homebridge # Update with path to your volume

Start the service by running:

$ systemctl --user start homebridge.service

Explanation

quadlet is a SystemD unit generator, located at /usr/lib/systemd/user-generators/podman-user-generator, it's a soft link to /usr/libexec/podman/quadlet

$ /usr/libexec/podman/quadlet -user -dryrun
quadlet-generator[29553]: Loading source unit file /home/xliang/.config/containers/systemd/homebridge.container
---homebridge.service---
[Unit]
Wants=podman-user-wait-network-online.service
After=podman-user-wait-network-online.service
Description=Homebridge Service
SourcePath=/home/xliang/.config/containers/systemd/homebridge.container
RequiresMountsFor=%t/containers

[Service]
Restart=always
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
ExecStop=/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
ExecStopPost=-/usr/bin/podman rm -v -f -i --cidfile=%t/%N.cid
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
ExecStart=/usr/bin/podman run --name homebridge --cidfile=%t/%N.cid --replace --rm --cgroups=split --network host --sdnotify=conmon -d -v %h/.containers/volumes/homebridge:/homebridge --label io.containers.autoupdate=registry --env TZ=America/Los_Angeles docker.io/homebridge/homebridge:latest

[Install]
WantedBy=default.target

[X-Container]
Image=docker.io/homebridge/homebridge:latest
AutoUpdate=registry
ContainerName=homebridge
Network=host
Environment=TZ=America/Los_Angeles
Volume=%h/.containers/volumes/homebridge:/homebridge

It basically reads the .container definition located under $HOME/.config/containers and generates an unit file for SystemD

#!/usr/bin/env bash
SYSTEMD_SERVICE_NAME="homebridge"
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
SYSTEMD_SERVICE_FILE="${SYSTEMD_USER_DIR}/${SYSTEMD_SERVICE_NAME}.service"
HOMEBRIDGE_VOLUME_DIR="$HOME/.containers/volumes/homebridge"
podman pull docker.io/homebridge/homebridge
mkdir -p $HOMEBRIDGE_VOLUME_DIR
if [[ -f "$SYSTEMD_SERVICE_FILE" ]]; then
echo 'Stopping the service currently running...'
systemctl --user stop $SYSTEMD_SERVICE_NAME
systemctl --user disable $SYSTEMD_SERVICE_NAME
rm -f $SYSTEMD_SERVICE_FILE
systemctl --user daemon-reload
podman system prune -f
fi
podman create \
--name $SYSTEMD_SERVICE_NAME \
--network host \
--env 'TZ=America/Los_Angeles' \
-v "$HOMEBRIDGE_VOLUME_DIR:/homebridge" \
docker.io/homebridge/homebridge
mkdir -p $SYSTEMD_USER_DIR
pushd $SYSTEMD_USER_DIR > /dev/null
podman generate systemd \
--new \
--files \
--container-prefix '' \
--pod-prefix '' \
--separator '' \
--name $SYSTEMD_SERVICE_NAME > /dev/null
popd > /dev/null
echo 'Starting the service...'
systemctl --user daemon-reload
systemctl --user enable $SYSTEMD_SERVICE_NAME
systemctl --user start $SYSTEMD_SERVICE_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment