Sync from upstream: ncp stop no longer misreports Ollama

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jon
2026-07-22 11:37:48 -05:00
co-authored by Claude Opus 4.8
parent ca8bc7425c
commit 9e639100cf
+12 -4
View File
@@ -199,11 +199,14 @@ def wait_for_port_close(port: int, timeout: int = 15) -> bool:
return False
def kill_matching(patterns, force=False) -> None:
def kill_matching(patterns, force=False) -> int:
"""The pkill -f sweep: catches reparented grandchildren (npm -> sh -> node
vite), uvicorn --reload workers, and instances started outside this CLI."""
vite), uvicorn --reload workers, and instances started outside this CLI.
Returns how many processes it signalled, so callers can stay quiet when
there was nothing to kill."""
ps = _psutil()
me = os.getpid()
hit = 0
for proc in ps.process_iter(["pid", "cmdline"]):
if proc.info["pid"] == me:
continue
@@ -211,8 +214,10 @@ def kill_matching(patterns, force=False) -> None:
if any(p in cmd for p in patterns):
try:
proc.kill() if force else proc.terminate()
hit += 1
except Exception:
pass
return hit
def kill_port(port: int) -> bool:
@@ -292,8 +297,11 @@ def stop_ollama() -> None:
return
except Exception:
pass
kill_matching(["ollama serve"])
print("NEXUS OLLAMA STOPPED (direct)")
# Silent when there was nothing to stop - the bash version only announced a
# direct kill if `pgrep ollama serve` actually matched, and claiming to have
# stopped a service that was never running is worse than saying nothing.
if kill_matching(["ollama serve"]):
print("NEXUS OLLAMA STOPPED (direct)")
# -- commands ------------------------------------------------------------------