Skip to content

Instantly share code, notes, and snippets.

@izzyleung
Created May 23, 2024 19:19
Show Gist options
  • Save izzyleung/ff5ec810fcd0f3a741748268887fb1fe to your computer and use it in GitHub Desktop.
Save izzyleung/ff5ec810fcd0f3a741748268887fb1fe to your computer and use it in GitHub Desktop.
Manage Homebridge as a SystemD service via Podman
#!/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