fix(gateway): treat SIGTERM under systemd as planned stop (exit 0)#41639
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(gateway): treat SIGTERM under systemd as planned stop (exit 0)#41639liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
When the gateway runs under a systemd unit, `systemctl stop` sends SIGTERM which the signal handler treated as an unexpected kill — exiting with code 1 and leaving the unit in "failed" state. Under systemd, SIGTERM is always intentional (systemctl stop, system shutdown, etc.). Treat it as a planned stop so the unit reports "inactive" instead of "failed". systemd's Restart=always (which the installed unit uses) restarts on any exit, so exit 0 is safe. Fixes NousResearch#41631
Contributor
Author
|
Thanks for flagging @alt-glitch. Comparing the two PRs:
The production code changes are equivalent, but #41642 has more comprehensive test coverage and integrates with the existing shutdown forensics system. Keeping #41642 open — happy to consolidate if #41639 is preferred by maintainers. |
Contributor
Author
2 tasks
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.
What does this PR do?
Treats SIGTERM under systemd as a planned stop (exit 0) instead of an unexpected kill (exit 1). When
systemctl stopsends SIGTERM, the gateway now exits cleanly so the unit reports "inactive" instead of "failed".Related Issue
Fixes #41631
Type of Change
Changes Made
gateway/run.py: Added systemd context check (INVOCATION_IDenv var) inshutdown_signal_handler— when running under systemd, SIGTERM is treated as a planned stop (exit 0). The unit usesRestart=always, so exit 0 is safe and avoids the spurious "failed" state.tests/gateway/test_systemd_sigterm_exit.py: 4 tests covering SIGTERM under systemd (planned), SIGTERM without systemd (unplanned), SIGINT always planned, and marker+systemd interaction.How to Test
hermes gateway install && hermes gateway startsystemctl --user stop hermes-gateway-<name>systemctl --user is-active hermes-gateway-<name>— should show "inactive" (not "failed")pytest tests/gateway/test_systemd_sigterm_exit.py -vChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AINVOCATION_IDenv var)Code Intelligence
gateway/run.py:shutdown_signal_handler(callers: signal handler registration vialoop.add_signal_handler)shutdown_forensics.snapshot_shutdown_contextalready detectsunder_systemdviaINVOCATION_ID;hermes_cli/gateway.pyinstalls units withRestart=always