fix: gracefully handle missing systemctl in container environments - #4415
Closed
dashed wants to merge 1 commit into
Closed
fix: gracefully handle missing systemctl in container environments#4415dashed wants to merge 1 commit into
dashed wants to merge 1 commit into
Conversation
dashed
marked this pull request as ready for review
April 1, 2026 08:21
dashed
marked this pull request as draft
April 1, 2026 08:23
dashed
force-pushed
the
fix/container-systemctl-status
branch
from
April 1, 2026 08:28
ee7df61 to
68de8a1
Compare
5 tasks
dashed
marked this pull request as ready for review
April 1, 2026 08:42
dashed
force-pushed
the
fix/container-systemctl-status
branch
from
April 4, 2026 17:28
68de8a1 to
598a286
Compare
hermes status and gateway status crash with FileNotFoundError when running in K8s containers that don't have systemd/systemctl. Detect container environments via KUBERNETES_SERVICE_HOST env var or missing systemctl binary, and show informative N/A output instead of crashing. Tests: 10 tests (4 unit for _is_container_env, 2 for systemd_status, 2 for _is_service_running, 2 e2e for full status output).
dashed
force-pushed
the
fix/container-systemctl-status
branch
from
April 7, 2026 11:41
598a286 to
937720b
Compare
Contributor
|
Closing as duplicate — this issue is fixed in #8614 (salvaged from @alt-glitch's comprehensive #8573). Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hermes statusandhermes gateway statuscrash withFileNotFoundErrorwhen running inside Docker/Kubernetes containers where systemd is not available.This PR adds container/K8s environment detection and shows proper gateway status using PID-based health checks instead of systemctl.
Before (container)
After (container)
The output matches the systemd path's format exactly (
✓ running/✗ stopped) — the only difference is the manager line showingcontainer/K8sinstead ofsystemd (user).Problem
On Linux,
show_status()andsystemd_status()unconditionally runsystemctl --user is-active hermes-gateway. Theexceptclause only catchesTimeoutExpired, notFileNotFoundError— so containers without systemd get an uncaught exception traceback.This affects any containerized deployment: Kubernetes pods, Docker containers, LXC, or any environment without systemd as the init system.
Fix
Container detection
New
_is_container_env()helper ingateway.pychecks:KUBERNETES_SERVICE_HOSTenv var (injected by K8s into every pod)shutil.which("systemctl")as fallback (catches Docker and other non-K8s containers)Gateway status in containers
Instead of showing "N/A", the container path uses
is_gateway_running()fromgateway.status— a PID-based liveness check that works in any environment:gateway.pidfromHERMES_HOMEos.kill(pid, 0)True/False→ displays✓ running/✗ stoppedFor
systemd_status()(thehermes gateway statuscommand), the container path also shows runtime details fromgateway_state.jsonwhen available (platform statuses, gateway state)._is_service_running()Returns
Falsein container environments — correct because there is no systemd service (the gateway process IS running, but not as a systemd unit).Changes
hermes_cli/gateway.py_is_container_env()helper; container-awaresystemd_status()with runtime details;_is_service_running()early returnhermes_cli/status.pyis_gateway_running()tests/hermes_cli/test_container_detection.pyBehavior matrix
✓ running/✗ stopped✓ running/✗ stopped, Manager:container/K8s✓ running/✗ stopped, Manager:container/K8sTest coverage
10 tests in
tests/hermes_cli/test_container_detection.py:TestIsContainerEnvTestSystemdStatusContainerTestIsServiceRunningContainerTestStatusOutputContainershow_status()output — container vs normal LinuxTest plan
hermes statusshows✓ running+container/K8sin K8s pod (verified on live deployment)hermes gateway statusshows running state with runtime details in containers