MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _start_background_proxy

Function _start_background_proxy

uncommon_route/cli.py:335–369  ·  view source on GitHub ↗
(
    *,
    port: int,
    host: str,
    upstream: str | None = None,
    composition_config: str = "",
)

Source from the content-addressed store, hash-verified

333
334
335def _start_background_proxy(
336 *,
337 port: int,
338 host: str,
339 upstream: str | None = None,
340 composition_config: str = "",
341) -> tuple[bool, str]:
342 _DATA_DIR.mkdir(parents=True, exist_ok=True, mode=0o700)
343 if _PID_FILE.exists():
344 try:
345 old_pid = int(_PID_FILE.read_text().strip())
346 except ValueError:
347 _PID_FILE.unlink(missing_ok=True)
348 else:
349 try:
350 os.kill(old_pid, 0)
351 return False, f"Already running (PID {old_pid}). Stop first: uncommon-route stop"
352 except OSError:
353 _PID_FILE.unlink(missing_ok=True)
354
355 cmd = [sys.executable, "-m", "uncommon_route.cli", "serve", "--port", str(port), "--host", host]
356 if upstream:
357 cmd.extend(["--upstream", upstream])
358 if composition_config:
359 cmd.extend(["--composition-config", composition_config])
360
361 with open(_LOG_FILE, "a") as lf:
362 proc = subprocess.Popen(
363 cmd,
364 stdout=lf,
365 stderr=subprocess.STDOUT,
366 start_new_session=True,
367 )
368 _PID_FILE.write_text(str(proc.pid))
369 return True, f"Started in background (PID {proc.pid})"
370
371
372def _parse_flags(args: list[str], known_flags: dict[str, bool]) -> tuple[dict[str, str | bool], list[str]]:

Callers 2

_cmd_serveFunction · 0.85
_cmd_initFunction · 0.85

Calls 1

openFunction · 0.85

Tested by

no test coverage detected