Skip to content

fix: auto-enable systemd linger during gateway install on headless servers#1023

Closed
teyrebaz33 wants to merge 1 commit intoNousResearch:mainfrom
teyrebaz33:fix/1005-gateway-linger-headless
Closed

fix: auto-enable systemd linger during gateway install on headless servers#1023
teyrebaz33 wants to merge 1 commit intoNousResearch:mainfrom
teyrebaz33:fix/1005-gateway-linger-headless

Conversation

@teyrebaz33
Copy link
Contributor

Fixes #1005

Problem

On headless servers, hermes gateway install sets up a user-level systemd service that stops when the SSH session ends — even though systemctl --user status shows active (running). Root cause: user services require linger to survive logout.

Solution (Option A + C from the issue)

New helper _ensure_linger_enabled() called at the end of systemd_install():

  1. Fast path: checks /var/lib/systemd/linger/<user> — no subprocess needed
  2. Auto-enable: runs loginctl enable-linger <user> — succeeds when the process has sufficient privileges (e.g. running as root or sudo-less loginctl access)
  3. Fallback: if loginctl fails, prints a clear, copy-pasteable warning:
⚠️  Linger not enabled — gateway will STOP when you close this terminal.

   On headless servers (VPS, cloud instances) you must run:
     sudo loginctl enable-linger <user>

   Then restart the gateway:
     systemctl --user restart hermes-gateway.service

Out of scope

Option B (--system flag for system-level service) — can follow in a separate PR.

Tests

4 new tests in TestEnsureLingerEnabled, 205 passed total.

…rvers

Fixes NousResearch#1005

Without linger, user-level systemd services stop when the SSH session
ends — even though systemctl --user status shows active (running).

Changes to systemd_install():
- Try loginctl enable-linger automatically (succeeds when the process
  has the required privileges)
- If loginctl fails (no privileges), print a clear, copy-pasteable
  warning with the exact command the user must run

New helper: _ensure_linger_enabled()
- Fast path: checks /var/lib/systemd/linger/<user> (no subprocess)
- Auto-enable: loginctl enable-linger <user>
- Fallback: actionable warning with sudo command + restart instructions

Tests: 4 new tests in TestEnsureLingerEnabled, 205 passed total
@teknium1
Copy link
Contributor

Merged via #1334. I cherry-picked your substantive linger auto-enable change onto current main, resolved it against the newer gateway unit-refresh flow, and added a small follow-up to handle missing SESSION UID USER SEAT LEADER CLASS TTY IDLE SINCE
1853 1000 teknium - 1072947 user - no -
1854 1000 teknium - 1072949 manager - no -
1855 1000 teknium - 1073653 user - no -
1857 1000 teknium seat0 1074425 user - yes 4h 38min ago

4 sessions listed. gracefully while keeping clear manual guidance/tests.

@teknium1 teknium1 closed this Mar 14, 2026
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.

Telegram gateway stops responding when terminal is closed on headless servers

2 participants