hermes-control-interface icon indicating copy to clipboard operation
hermes-control-interface copied to clipboard

HCI gateway status detection should not depend entirely on systemctl

Open tiangao88 opened this issue 7 months ago • 1 comments

HCI gateway status detection should not depend entirely on systemctl

Summary

I ran into a gateway-status issue on a host where Hermes is healthy and reachable, but not managed by systemd.

HCI was able to reach the Hermes Gateway API, but parts of the UI still reported the gateway as stopped or disabled because they appeared to rely on systemctl as the source of truth.

This seems like a general compatibility issue for non-systemd installs, not just a host-specific edge case.

Environment

  • HCI version: v3.4.2
  • Hermes gateway API enabled and healthy
  • Hermes managed outside systemd
  • Example setup: a supervisor-managed Hermes gateway exposing a healthy local API on 127.0.0.1:8642

What I saw

Initially, HCI could not discover the gateway port for default, fell back to CLI mode, and showed Gateway API Enabled as disabled.

After declaring the API server in Hermes config:

platforms:
  api_server:
    enabled: true
    extra:
      host: 127.0.0.1
      port: 8642

HCI started discovering the gateway correctly.

At that point:

  • HCI discovered default: 8642
  • the gateway health endpoints returned 200
  • profile-level gateway checks could look healthy

But some parts of the UI, especially summary/service-status views, still showed the gateway as stopped or disabled.

Why this seems to happen

From what I could tell, HCI has a few different gateway-status paths:

  1. API/gateway discovery

    • based on config, discovered port, and API reachability
  2. Gateway service card / diagnostics

    • in some places based on systemctl is-active, systemctl is-enabled, and systemctl status
  3. Home/dashboard summary

    • in some places based on systemctl is-active hermes-gateway

So the API side can be healthy while the UI still shows a false negative status because systemctl is being treated as the main signal.

Expected behavior

If Hermes config declares an API server and HCI can confirm that:

  • the configured port exists
  • the local health endpoint responds successfully

then HCI should treat the gateway as running, even if there is no systemd unit behind it.

Similarly:

  • Enabled should come from config when platforms.api_server.enabled is present
  • systemctl should be a fallback for installs that actually use it, not the default truth source for every environment

Suggested approach

For setups where an API server is configured:

  • prefer platforms.api_server.enabled over systemctl is-enabled
  • prefer a successful local gateway health probe over systemctl is-active
  • use a more generic service label when the gateway is not managed by systemd
  • keep the current systemctl behavior as fallback when no configured API server is present

Why this would help

This would make HCI work better on:

  • non-systemd Linux hosts
  • containerized deployments
  • custom supervisors
  • externally managed Hermes runtimes

In all of those cases, the gateway can be perfectly healthy while systemctl is simply not relevant.

Final note

I am not suggesting removing systemctl support.

The issue is that systemctl seems to be assumed in some UI paths even when HCI already has a better signal available from config and the local gateway health endpoint.

tiangao88 avatar Apr 23 '26 08:04 tiangao88

✅ Fixed — commit f12abaa

Root Cause

HCI relied on systemctl is-active as the primary signal for gateway status. Non-systemd setups (container, supervisor, custom runtimes) showed gateway as "stopped" even when the API was healthy.

Changes

New: probeGatewayHealth(profile) — centralized health probe function:

  • Probes gateway /health endpoint directly (3s timeout)
  • Falls back to systemctl if no API configured
  • Returns { ok, managedBy: 'api' | 'systemd' | 'unknown' }

Updated 3 endpoints:

  1. /api/agent/status — gateway status now uses API probe first, systemctl fallback
  2. /api/gateway/:profile — service card returns managedBy field; API-healthy = active: true, enabled: true
  3. /api/gateway/:profile/health — 3-tier check: API probe → systemctl → port listening

Behavior

  • Non-systemd setups: Gateway shows "running" if API health probe succeeds
  • Systemd setups: Same behavior (systemctl still works as fallback)
  • No API configured: Falls back to systemctl (backwards compatible)
  • Response includes managedBy: 'api' | 'systemd' | 'unknown' — frontend can show appropriate labels

Tested

  • Gateway health probe returns 200 on http://127.0.0.1:8642/health
  • Systemctl fallback still works for systemd-managed gateways
  • Merged to main, deployed to staging

xaspx avatar May 03 '26 18:05 xaspx