Created
May 23, 2024 19:19
-
-
Save izzyleung/ff5ec810fcd0f3a741748268887fb1fe to your computer and use it in GitHub Desktop.
Manage Homebridge as a SystemD service via Podman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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