Files
claude-foundations/scripts/install-systemd.sh
Paul O'Reilly 53170c320e feat: add systemd service config and install script
config/systemd/user/claude-sessions-save.service: source of truth
for the shutdown service, version-controlled alongside the scripts
it calls.

scripts/install-systemd.sh: idempotent install script — copies the
service file to ~/.config/systemd/user/, reloads the daemon, and
enables + starts the service. Run on any new machine to wire up
graceful Claude session shutdown.
2026-10-12 16:11:18 +13:00

52 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# install-systemd.sh — Install claude-sessions systemd user service.
#
# Copies the service file from this repo into ~/.config/systemd/user/,
# reloads the daemon, and enables + starts the service.
#
# Safe to re-run (idempotent).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
SRC="$REPO_DIR/config/systemd/user/claude-sessions-save.service"
DST_DIR="$HOME/.config/systemd/user"
DST="$DST_DIR/claude-sessions-save.service"
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
ok() { echo -e "${GREEN}OK${NC} $*"; }
skip() { echo -e "${YELLOW}SKIP${NC} $*"; }
[[ -f "$SRC" ]] || { echo "ERROR: source not found: $SRC" >&2; exit 1; }
mkdir -p "$DST_DIR"
if [[ -f "$DST" ]] && diff -q "$SRC" "$DST" &>/dev/null; then
skip "service file already up to date"
else
cp "$SRC" "$DST"
ok "installed $DST"
fi
systemctl --user daemon-reload
ok "daemon reloaded"
if systemctl --user is-enabled --quiet claude-sessions-save.service 2>/dev/null; then
skip "already enabled"
else
systemctl --user enable claude-sessions-save.service
ok "enabled claude-sessions-save.service"
fi
if systemctl --user is-active --quiet claude-sessions-save.service 2>/dev/null; then
skip "already active"
else
systemctl --user start claude-sessions-save.service
ok "started claude-sessions-save.service"
fi
echo ""
echo "claude-sessions-save.service is enabled and active."
echo "It will gracefully exit Claude tmux sessions at shutdown."