Skip to content

Telegram gateway stops responding when terminal is closed on headless servers #1005

@nova328

Description

@nova328

Telegram gateway stops responding when terminal is closed on headless servers

Problem

On headless servers (Digital Ocean droplets, VPS, etc.), the Telegram/Discord/WhatsApp gateway stops responding to messages when the SSH terminal is closed, even though hermes gateway install was run and systemctl --user status hermes-gateway.service shows "active (running)".

Root Cause

The gateway is installed as a systemd user-level service (~/.config/systemd/user/hermes-gateway.service), but user-level services are automatically stopped when the user logs out unless linger is enabled via:

sudo loginctl enable-linger <username>

Without this, the user's systemd manager (sd-pam) terminates on logout, killing all user services including the gateway.

Current Workaround

Users must manually enable linger after installation:

# Enable linger for the user
sudo loginctl enable-linger hermesagent

# Restart the gateway
systemctl --user restart hermes-gateway.service

Expected Behavior

The documentation or installation should either:

  1. Auto-enable linger during hermes gateway install if running with sudo privileges
  2. Clear error message explaining that linger must be enabled for headless operation
  3. Document this requirement prominently in the setup guide
  4. Provide a systemd system service option (user-level vs system-level) for headless deployments

Impact

  • Headless servers: Telegram/Discord/WhatsApp integrations break on SSH logout
  • Production deployments: Service appears running but doesn't respond to messages
  • User confusion: systemctl --user status shows "active (running)" but messages aren't received
  • User frustration: Users think the installation failed when it's actually a configuration requirement

Environment

  • OS: Linux (headless VPS/Digital Ocean droplet)
  • Hermes Agent: Latest version (installable via pip)
  • Gateway: Installed via hermes gateway install
  • Services: User-level systemd services (~/.config/systemd/user/)

Suggested Fixes

Option A: Auto-detect and enable linger during install

# During `hermes gateway install`:
if [ "$(id -u)" = "0" ]; then
    echo "Enabling linger for headless operation..."
    loginctl enable-linger "$USER"
fi

Option B: Add system-level service option

# Allow users to install as a system service instead of user service
hermes gateway install --system  # Install as system service (persists across logins)

Option C: Clear warning message in documentation

⚠️ On headless servers (VPS, cloud instances), you must run this after installation:

sudo loginctl enable-linger $USER

Without this, the gateway will stop when you disconnect SSH.

Testing

To verify the issue exists:

  1. Install Hermes Agent
  2. Run hermes gateway install
  3. Start Telegram in hermes gateway
  4. Close SSH terminal
  5. Check if Telegram still responds (it won't without linger)

Related Issues

  • This is a common systemd limitation for user services on headless systems
  • Similar issues exist with other tools that use user-level services (e.g., docker services, custom daemons)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions