Add a systemd user service and installer for the stage simulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-10-22 13:29:23 +13:00
1 parent 20f018a523
commit df05c8ca49
3 files changed
+85

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Install the stage simulator as a systemd user service and start it.
#
# simulator/systemd/install.sh # install, enable, start
# simulator/systemd/install.sh --show shows/test.qxw # pass options to the simulator
# simulator/systemd/install.sh --no-enable # install only; start it with
# # systemctl --user start simulator
# simulator/systemd/install.sh --uninstall
#
# Logs: journalctl --user -u simulator -f
set -euo pipefail
UNIT=simulator.service
HERE="$(cd "$(dirname "$0")" && pwd)"
ROOT="$(cd "$HERE/../.." && pwd)"
DEST="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
if [[ "${1:-}" == "--uninstall" ]]; then
systemctl --user disable --now "$UNIT" 2>/dev/null || true
rm -f "$DEST/$UNIT"
systemctl --user daemon-reload
echo "Removed $UNIT."
exit 0
fi
PYTHON="$ROOT/.venv/bin/python"
[[ -x "$PYTHON" ]] || PYTHON="$(command -v python3)"
ENABLE=1
if [[ "${1:-}" == "--no-enable" ]]; then
ENABLE=
shift
fi
ARGS="$*"
mkdir -p "$DEST"
sed -e "s|@ROOT@|$ROOT|g" -e "s|@PYTHON@|$PYTHON|g" -e "s|@ARGS@|$ARGS|g" \
"$HERE/$UNIT" >"$DEST/$UNIT"
systemctl --user daemon-reload
if [[ -z "$ENABLE" ]]; then
# Undo an earlier enable, so it does not start at login here.
systemctl --user disable "$UNIT" 2>/dev/null || true
echo "Installed $DEST/$UNIT. It does not start at login."
echo "Start it with: systemctl --user start simulator"
exit 0
fi
systemctl --user enable "$UNIT"
systemctl --user restart "$UNIT"
echo "Installed $DEST/$UNIT and started it."
systemctl --user --no-pager status "$UNIT" | head -5 || true
+20
View File
@@ -0,0 +1,20 @@
# Stage simulator (python -m simulator) as a systemd user service.
# install.sh fills in @ROOT@, @PYTHON@ and @ARGS@ and copies it to
# ~/.config/systemd/user/.
[Unit]
Description=Stage simulator (Art-Net on 6454, view on http://127.0.0.1:8765)
After=network.target
[Service]
Type=simple
WorkingDirectory=@ROOT@
ExecStart=@PYTHON@ -m simulator @ARGS@
Environment=PYTHONUNBUFFERED=1
# The simulator shuts its server and Art-Net socket down on Ctrl+C.
KillSignal=SIGINT
Restart=on-failure
RestartSec=3
[Install]
WantedBy=default.target