fix(gateway): adopt unit's HERMES_HOME for --system CLI ops (salvage #22533)#22803
Merged
Conversation
Contributor
🔎 Lint report:
|
When systemd_restart / systemd_status / systemd_stop run under sudo, HERMES_HOME is stripped and HOME=/root, so get_hermes_home() resolves to /root/.hermes instead of the unit's pinned home. read_runtime_status and get_running_pid then look at the wrong gateway_state.json — the 60s status poll never sees "running", times out, and forces another systemctl restart that SIGTERMs the in-progress new gateway. Read the unit's pinned HERMES_HOME from `systemctl show -p Environment` and mirror it into os.environ before any HERMES_HOME-derived read. Early-out when system=False (user-scope inherits naturally). Errors swallowed so a transient systemctl failure doesn't break unrelated CLI ops. Closes #22035.
13 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.
Summary
Salvage of #22533 —
hermes gateway restart --system(andstatus/stop) now read the gateway's actual runtime state under sudo instead of looking in/root/.hermes/.Root cause
Under
sudo,HERMES_HOMEis stripped from the env andHOME=/root, soget_hermes_home()returns/root/.hermes.read_runtime_status()andget_running_pid()derive their paths from that — they look forgateway_state.jsonin/root/.hermes/while the actually-running gateway wrote it under the unit's pinnedHERMES_HOME=/home/<user>/.hermes/._wait_for_systemd_service_restartpollsread_runtime_status()for 60s, never seesrunning, times out, then forces anothersystemctl restartthat SIGTERMs the in-progress new gateway.Changes (contributor commit, re-authored to mbac)
hermes_cli/gateway.py: read the unit's pinnedEnvironment=viasystemctl show -p Environment, parseHERMES_HOME=..., and mirror it intoos.environbefore any HERMES_HOME-derived read in the three--systementrypoints (systemd_restart,systemd_status,systemd_stop). Early-out whensystem=False(user-scope inherits naturally). Errors swallowed so a transientsystemctlfailure doesn't break unrelated CLI ops.Note: original PR was opened by mbac but committed locally as
Test User <test@example.com>(default git config). Cherry-picked + re-authored tombac <308068+mbac@users.noreply.github.com>to preserve attribution.Validation
Closes #22035 via salvage.