in src/databao_context_engine/llm/runtime.py [0:0]
def start_if_needed(self) -> subprocess.Popen | None:
if self._service.is_healthy():
return None
logger.info("Ollama server not running. Starting Ollama server...")
cmd = [self._config.bin_path, "serve"]
env = os.environ.copy()
env["OLLAMA_HOST"] = f"{self._config.host}:{self._config.port}"
if self._config.extra_env:
env.update(self._config.extra_env)
stdout = subprocess.DEVNULL
proc = subprocess.Popen(
cmd,
cwd=str(self._config.work_dir) if self._config.work_dir else None,
env=env,
stdout=stdout,
stderr=subprocess.STDOUT,
text=False,
close_fds=os.name != "nt",
)
return proc