fix(@scripts): 🐛 improve detached session systemd handling
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
d4359d4d56
commit
7eabb4fcff
1 changed files with 15 additions and 6 deletions
21
bin/rclaude
21
bin/rclaude
|
|
@ -1604,14 +1604,23 @@ inner=$(build_inner "$dir")
|
||||||
# detached branch above; used by supervisor processes (e.g. clare web)
|
# detached branch above; used by supervisor processes (e.g. clare web)
|
||||||
# that bring up a remote Claude pane without attaching the calling tty.
|
# that bring up a remote Claude pane without attaching the calling tty.
|
||||||
#
|
#
|
||||||
# We wrap `tmux new-session -d` in `systemd-run --user --scope --collect`
|
# We launch tmux inside a transient `systemd-run --user --unit=<name>`
|
||||||
# so the tmux server is parented to its own systemd scope, not the ssh
|
# user service rather than the calling ssh session's scope, with
|
||||||
# login session's scope. Without this, systemd-logind reaps the tmux
|
# Restart=on-failure so a tmux server crash (heap-corruption bugs in
|
||||||
# server when the ssh session ends — even with `loginctl enable-linger`,
|
# older tmux builds, OOM-kill, etc.) is automatically recovered by
|
||||||
# transient ssh-spawn scopes get cleaned up after disconnect. The
|
# systemd rather than waiting on Clare's 60s supervisor heartbeat.
|
||||||
# `--collect` flag lets systemd garbage-collect the scope after exit.
|
#
|
||||||
|
# `--scope` was the old approach but a scope dies with its process — no
|
||||||
|
# restart. Falls back to a plain detached `tmux new-session -d` if the
|
||||||
|
# remote host has no systemd-run (e.g. macOS).
|
||||||
# Mosh is interactive-only — always go through ssh for detached spawn.
|
# Mosh is interactive-only — always go through ssh for detached spawn.
|
||||||
if [ -n "${RCLAUDE_DETACHED:-}" ]; then
|
if [ -n "${RCLAUDE_DETACHED:-}" ]; then
|
||||||
|
# Run tmux inside a transient user scope so the tmux daemon escapes
|
||||||
|
# the calling ssh login session's cgroup (which systemd-logind would
|
||||||
|
# otherwise reap on disconnect, even with linger enabled). `--scope`
|
||||||
|
# exits as soon as the tmux daemon detaches; recovery from later
|
||||||
|
# tmux crashes is handled by Clare's supervisor heartbeat in
|
||||||
|
# `clare web` (re-runs ensure_running every 60s).
|
||||||
_remote_cmd="systemd-run --user --scope --collect --quiet tmux new-session -d -s '${session}' \"${inner}\" 2>/dev/null || tmux new-session -d -s '${session}' \"${inner}\""
|
_remote_cmd="systemd-run --user --scope --collect --quiet tmux new-session -d -s '${session}' \"${inner}\" 2>/dev/null || tmux new-session -d -s '${session}' \"${inner}\""
|
||||||
ssh $_SSH_LIVE_OPTS "$host" "$_remote_cmd"
|
ssh $_SSH_LIVE_OPTS "$host" "$_remote_cmd"
|
||||||
printf '%s\n' "$session"
|
printf '%s\n' "$session"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue