fix(gateway): write planned-stop marker from systemd ExecStop#42555
fix(gateway): write planned-stop marker from systemd ExecStop#42555izumi0uu wants to merge 1 commit into
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Overview
This PR adds a planned-stop helper that writes a marker file when systemd ExecStop fires, enabling clean gateway shutdown.
Changes
- Adds gateway_planned_stop_helper command
- Adds ExecStop to systemd unit files
- Good test coverage
Quality
- Clean fix with proper subprocess handling using shlex.quote
- No security concerns
Reviewed by Hermes Agent
|
Heads-up for context (not asking to close this): #43236 just merged, fixing the Docker/s6 side of the autostart problem (#42675) by reusing the planned-stop marker — including writing the marker from This PR targets the systemd |
Make generated systemd units write the planned-stop marker from ExecStop before systemd delivers SIGTERM to the gateway process. This keeps `systemctl stop` on the existing planned-stop path instead of teaching the signal handler to guess who sent SIGTERM. The helper is a hidden `hermes gateway planned-stop-helper --pid $MAINPID` subcommand so the unit can mark the target process without recursively calling `hermes gateway stop` from ExecStop. Constraint: systemd stop and unexpected external SIGTERM are indistinguishable inside the signal handler Rejected: infer SIGTERM source from INVOCATION_ID or under_systemd flags | those only prove the runtime, not the sender Confidence: high Scope-risk: narrow Directive: Keep planned-stop classification on the service stop path rather than adding more SIGTERM-source heuristics Tested: pytest tests/hermes_cli/test_gateway_service.py -q -k 'planned_stop_helper or avoids_recursive_execstop or system_unit_has_no_root_paths or systemd_stop_marks_running_gateway_as_planned_stop' Tested: pytest tests/hermes_cli/test_systemd_optional_directives.py -q Tested: pytest tests/hermes_cli/test_gateway_service.py -q -k 'systemd_unit_uses_dot_venv_when_detected or systemd_unit_includes_profile or system_unit_includes_wsl_windows_interop_paths or user_unit_includes_resolved_node_directory_in_path' Not-tested: live systemctl stop against an installed Linux systemd unit
27ad135 to
b4c6a37
Compare
|
Rebased onto the latest main and re-verified the relevant gateway and systemd tests. No changes to the PR diff, just replayed on top of the latest main. |
What does this PR do?
Routes
systemctl stopthrough the existing planned-stop marker path instead of trying to infer who sentSIGTERMinside the gateway.The generated systemd unit now includes an
ExecStophelper that writes the planned-stop marker for$MAINPIDbefore systemd deliversSIGTERM. That keeps intentional service stops on the same clean-shutdown path already used byhermes gateway stop, while leaving unexpected externalSIGTERMhandling unchanged.This follows the direction in #42517 and avoids the
INVOCATION_ID/under_systemdinference problem discussed against #41642 and #41690.Related Issue
Fixes #42517
Type of Change
Changes Made
hermes gateway planned-stop-helper --pid <pid>subcommand for service-managed stop flowsExecStop=<python> -m hermes_cli.main gateway planned-stop-helper --pid $MAINPIDExecStopnon-recursive:hermes gateway stopExecStoppresence in generated units$MAINPIDHow to Test
ExecStop=... gateway planned-stop-helper --pid $MAINPID.systemctl --user stop <service>(or system scope as appropriate).INVOCATION_ID-based signal-source inference.Targeted local validation:
Checklist
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/AScreenshots / Logs
N/A