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:
1 parent
20f018a523
commit
df05c8ca49
3 files changed
+85
No files matched your search
Executable
+51
@@ -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
|
||||
Reference in new issue
Block a user