forked from enderofwings/NexusOS
feat: add portable NexusOS CLI and packaging
This commit is contained in:
@@ -20,7 +20,9 @@ _log = logging.getLogger("nexus.ollama")
|
||||
_ollama_manager = None
|
||||
|
||||
# Bundled binary ships alongside the project; fall back to system PATH
|
||||
_BUNDLED_OLLAMA = Path(__file__).resolve().parent.parent / "ollama" / "bin" / "ollama"
|
||||
_BUNDLED_OLLAMA = settings.project_root / "ollama" / "bin" / (
|
||||
"ollama.exe" if os.name == "nt" else "ollama"
|
||||
)
|
||||
|
||||
# POSIX: detach the child into its own session so we can signal the whole group.
|
||||
# Windows has no setsid/killpg — run the child normally and terminate() it.
|
||||
@@ -340,7 +342,7 @@ class OllamaManager:
|
||||
self.running = False
|
||||
self._available = None # see is_available()
|
||||
|
||||
self.runtime_dir = Path(runtime_dir) if runtime_dir else Path(__file__).resolve().parent.parent / "runtime"
|
||||
self.runtime_dir = Path(runtime_dir) if runtime_dir else settings.runtime_dir
|
||||
(self.runtime_dir / "logs").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
self.log_file = self.runtime_dir / "logs" / "ollama.log"
|
||||
@@ -406,6 +408,10 @@ class OllamaManager:
|
||||
return env
|
||||
|
||||
def is_available(self):
|
||||
if not settings.manage_ollama:
|
||||
# A remote provider has no local executable to discover. Availability
|
||||
# means it is configured; is_running() performs the live probe.
|
||||
return True
|
||||
# ponytail: cached for the life of the process. This spawns a subprocess,
|
||||
# and /status calls it on every poll - the frontend polls continuously,
|
||||
# so it was a process spawn per tick to answer a question whose answer
|
||||
@@ -433,6 +439,9 @@ class OllamaManager:
|
||||
return False
|
||||
|
||||
def start(self):
|
||||
if not settings.manage_ollama:
|
||||
_log.info("Remote Ollama is externally managed at %s", self._api_base)
|
||||
return self.is_running()
|
||||
if not self.is_available():
|
||||
_log.warning("Ollama not found at %s; skipping startup", _ollama_bin())
|
||||
return False
|
||||
@@ -474,6 +483,9 @@ class OllamaManager:
|
||||
|
||||
async def start_async(self):
|
||||
"""Async-safe version of start() for use inside async startup handlers."""
|
||||
if not settings.manage_ollama:
|
||||
_log.info("Remote Ollama is externally managed at %s", self._api_base)
|
||||
return self.is_running()
|
||||
if not self.is_available():
|
||||
_log.warning("Ollama not found at %s; skipping startup", _ollama_bin())
|
||||
return False
|
||||
@@ -514,6 +526,9 @@ class OllamaManager:
|
||||
return False
|
||||
|
||||
def stop(self):
|
||||
if not settings.manage_ollama:
|
||||
_log.info("Not stopping externally managed Ollama at %s", self._api_base)
|
||||
return False
|
||||
# Terminate a server we spawned ourselves.
|
||||
if self.process:
|
||||
try:
|
||||
@@ -902,4 +917,4 @@ def shutdown_ollama() -> None:
|
||||
global _ollama_manager
|
||||
if _ollama_manager is not None:
|
||||
_ollama_manager.stop()
|
||||
_ollama_manager = None
|
||||
_ollama_manager = None
|
||||
|
||||
Reference in New Issue
Block a user