Sync from upstream: ncp stop no longer misreports Ollama
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+12
-4
@@ -199,11 +199,14 @@ def wait_for_port_close(port: int, timeout: int = 15) -> bool:
|
|||||||
return False
|
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
|
"""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()
|
ps = _psutil()
|
||||||
me = os.getpid()
|
me = os.getpid()
|
||||||
|
hit = 0
|
||||||
for proc in ps.process_iter(["pid", "cmdline"]):
|
for proc in ps.process_iter(["pid", "cmdline"]):
|
||||||
if proc.info["pid"] == me:
|
if proc.info["pid"] == me:
|
||||||
continue
|
continue
|
||||||
@@ -211,8 +214,10 @@ def kill_matching(patterns, force=False) -> None:
|
|||||||
if any(p in cmd for p in patterns):
|
if any(p in cmd for p in patterns):
|
||||||
try:
|
try:
|
||||||
proc.kill() if force else proc.terminate()
|
proc.kill() if force else proc.terminate()
|
||||||
|
hit += 1
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
return hit
|
||||||
|
|
||||||
|
|
||||||
def kill_port(port: int) -> bool:
|
def kill_port(port: int) -> bool:
|
||||||
@@ -292,8 +297,11 @@ def stop_ollama() -> None:
|
|||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
kill_matching(["ollama serve"])
|
# Silent when there was nothing to stop - the bash version only announced a
|
||||||
print("NEXUS OLLAMA STOPPED (direct)")
|
# 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 ------------------------------------------------------------------
|
# -- commands ------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user