Add sessions-ctl and systemd units for the dev box
sessions-ctl creates, starts, stops and lists Claude Code sessions. Each one is a checkout in ~/sessions/<name>, a state file and a systemd user unit that runs claude with Remote Control in its own tmux server. Sessions are restarted if they crash, come back at boot (linger), and resume the same conversation by a pinned session UUID. Over SSH it runs as a forced command: only list/repos/status/create/start/ stop/health are accepted, arguments are validated, and nothing reaches a shell or Claude as a prompt. refresh-access keeps the key's from= restriction in sync with the IP of reudy.net (hourly timer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1816f6f863
7 changed files with 754 additions and 0 deletions
32
dev/systemd/claude-session@.service
Normal file
32
dev/systemd/claude-session@.service
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# One Claude Code session with Remote Control, inside its own tmux server.
|
||||
# Managed by sessions-ctl: `enable --now` = run now and at every boot,
|
||||
# `disable --now` = stop and stay stopped. Needs linger for boot start.
|
||||
[Unit]
|
||||
Description=Claude Code session %i
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
# Give up after 5 crashes in 10 minutes instead of looping forever.
|
||||
StartLimitIntervalSec=600
|
||||
StartLimitBurst=5
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
# systemd user units get a bare environment; claude lives in ~/.local/bin.
|
||||
Environment=PATH=%h/.local/bin:/usr/local/bin:/usr/bin:/bin
|
||||
# tmux (built with systemd support) moves every pane into its own
|
||||
# tmux-spawn-*.scope over the user D-Bus, which would take claude out of this
|
||||
# unit's cgroup — escaping MemoryMax and a clean stop. With no bus to reach,
|
||||
# the move fails harmlessly and claude stays here. Nothing in a session needs D-Bus.
|
||||
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/nonexistent
|
||||
ExecStart=%h/.local/bin/sessions-ctl _launch %i
|
||||
PIDFile=%t/claude-session/%i.pid
|
||||
ExecStop=/usr/bin/tmux -L claude-%i kill-server
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
TimeoutStartSec=60
|
||||
# The box has ~4 GB; keep one runaway session from taking the rest down.
|
||||
MemoryHigh=1200M
|
||||
MemoryMax=1600M
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
10
dev/systemd/sessions-access-refresh.service
Normal file
10
dev/systemd/sessions-access-refresh.service
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Re-resolve ssh_access.allow_from_host (e.g. reudy.net) and update the
|
||||
# from="…" restriction on prod's key in ~/.ssh/authorized_keys if the IP moved.
|
||||
[Unit]
|
||||
Description=Refresh the source-IP restriction on the session-manager SSH key
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=%h/.local/bin/sessions-ctl refresh-access
|
||||
10
dev/systemd/sessions-access-refresh.timer
Normal file
10
dev/systemd/sessions-access-refresh.timer
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Hourly refresh of the session-manager SSH key source IP
|
||||
|
||||
[Timer]
|
||||
OnBootSec=2min
|
||||
OnUnitActiveSec=1h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue