Skip to content

Session daemons under systemd (Linux) and launchd (macOS); hqsh server setup - #3

Merged
ralyodio merged 1 commit into
mainfrom
feat/service-managers
Oct 6, 2026
Merged

ralyodio merged 1 commit into
mainfrom
feat/service-managers

Conversation

@ralyodio

@ralyodio ralyodio commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Anthony: "it should use systemd on *nix for hqsh server", and it must work on every server/device.

  • Linux: each session's daemon is a transient user unit hqsh-<session>.service (systemd-run --user --collect). It is used only with lingering on, since without it logind stops user units at the last logout; then it falls back to the detached fork.
  • macOS: a launchd job sh.hqterm.hqsh.<session> bootstrapped into user/<uid>, with the plist kept beside the sockets (not LaunchAgents, so it does not start at login).
  • Everywhere else, or when a manager refuses: the existing setsid fork, so a session always starts if it can start at all.
  • hqsh server setup [--check] reports the supervisor and enables lingering. HQSH_SUPERVISOR=fork|systemd|launchd|auto overrides.
  • Bug caught by the real-systemd test: systemctl --user finds the manager through XDG_RUNTIME_DIR, which is also hqsh's socket dir. The systemd commands now target /run/user/UID, and the unit is handed the attaching side's XDG_RUNTIME_DIR/HOME/SHELL.

Tests

  • Supervisor choice across 9 host shapes, linger enabling, unit-name escaping, systemd-run args, env passing, plist escaping.
  • TestSessionRunsUnderTheRealServiceManager passed on dev2 under real systemd: the unit was active, served an attach, and was collected on exit. On macOS CI it exercises launchd; elsewhere it skips.
  • go vet passes for linux, darwin and windows.

The Windows server (ConPTY) follows in its own PR; this keeps the Windows stub.

🤖 Generated with Claude Code

…erver setup

Each session's daemon now starts as a systemd user unit hqsh-<session>.service
(with lingering, so it survives logout) or a launchd job in user/<uid>, falling
back to the detached fork. hqsh server setup [--check] reports which applies
and enables lingering. HQSH_SUPERVISOR overrides the choice.

systemctl/systemd-run are pointed at /run/user/UID, and the unit gets the
attaching side's XDG_RUNTIME_DIR, HOME and SHELL, so the socket lands where
attach dials even when the two runtime dirs differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit ddbdcda into main Oct 6, 2026
3 of 5 checks passed
@ralyodio
ralyodio deleted the feat/service-managers branch October 6, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant