fix(update): sudo-prefix the manual kickstart hint for a LaunchDaemon run as a user
`launchctl kickstart system/<label>` needs root. When a LaunchDaemon-supervised backend does not come back and `hermes update` runs as a regular user, the manual hint now reads `sudo launchctl kickstart -k system/<label>`, so the operator gets a command that works from the shell they are in. LaunchAgent (gui/user domain) hints are unchanged.
This commit is contained in:
@@ -447,8 +447,11 @@ def _restart_killed_backends(
|
||||
if _dash._restart_launchd_job(domain, label, old_pid):
|
||||
print(f" ✓ restarted launchd job {target}")
|
||||
else:
|
||||
# A LaunchDaemon (system domain) can only be kickstarted by root; the hint must
|
||||
# be the command that works from the shell the operator is actually in.
|
||||
sudo = "sudo " if domain.startswith("system") and os.geteuid() != 0 else "" # windows-footgun: ok — launchd jobs exist only on macOS
|
||||
failed_restarts.append(
|
||||
(target, f"launchd is not supervising a fresh process; run: launchctl kickstart -k {target}"))
|
||||
(target, f"launchd is not supervising a fresh process; run: {sudo}launchctl kickstart -k {target}"))
|
||||
unrecovered.append(pid)
|
||||
elif pid in pid_cmdline:
|
||||
respawn_candidates.append((pid, pid_cmdline[pid], pid_home.get(pid)))
|
||||
|
||||
@@ -993,7 +993,12 @@ class TestLaunchdSupervisedBackends:
|
||||
restart_ok=False)
|
||||
respawn.assert_not_called()
|
||||
assert result["unrecovered"] == [9103]
|
||||
assert "launchctl kickstart -k gui/501/ai.hermes.dashboard" in capsys.readouterr().out
|
||||
assert "run: launchctl kickstart -k gui/501/ai.hermes.dashboard" in capsys.readouterr().out
|
||||
|
||||
# A LaunchDaemon lives in the system domain: kickstart needs root, so a non-root hint says sudo.
|
||||
with patch("hermes_cli.dashboard_procs.os.geteuid", return_value=501, create=True): # windows-footgun: ok — patch target string, create=True
|
||||
self._run(9105, [("system", "ai.hermes.serve", list(self.ARGV), None)], restart_ok=False)
|
||||
assert "run: sudo launchctl kickstart -k system/ai.hermes.serve" in capsys.readouterr().out
|
||||
|
||||
other = ("gui/501", "ai.hermes.other", ["hermes", "dashboard", "--port", "8300"], 777)
|
||||
result, restart, respawn = self._run(9104, [other])
|
||||
|
||||
Reference in New Issue
Block a user