129 lines
3.5 KiB
Python
129 lines
3.5 KiB
Python
"""Production server command for @model-boss.
|
|
|
|
Starts production servers using configuration from infrastructure/ports.production.yaml.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from service_config import get_service_config, list_services
|
|
|
|
|
|
def prod_command(args: list[str], workspace_root: Path) -> int:
|
|
"""Start production servers.
|
|
|
|
Args:
|
|
args: Command-line arguments
|
|
workspace_root: Path to workspace root
|
|
|
|
Returns:
|
|
Exit code (0 = success, non-zero = failure)
|
|
"""
|
|
services = list_services("prod")
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog="./run prod",
|
|
description="Start production servers",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
./run prod coordinator # Start coordinator on prod port
|
|
./run prod llama-http # Start LLM backend on prod port
|
|
./run prod --list # List prod services with settings
|
|
|
|
Note: Production ports are dev + 10000 (e.g., 8210 -> 18210).
|
|
This allows running dev and prod simultaneously.
|
|
""",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"service",
|
|
nargs="?",
|
|
choices=services,
|
|
help="Service to start",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--list",
|
|
action="store_true",
|
|
help="List available services with production settings",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--workers",
|
|
type=int,
|
|
help="Override worker count",
|
|
)
|
|
|
|
parser.add_argument(
|
|
"--log-level",
|
|
help="Override log level",
|
|
)
|
|
|
|
parsed = parser.parse_args(args)
|
|
|
|
if parsed.list:
|
|
print("Production services:\n")
|
|
for svc_id in services:
|
|
cfg = get_service_config(svc_id, "prod")
|
|
timeout = cfg["timeout_keep_alive"]
|
|
print(
|
|
f" {svc_id:15} port {cfg['port']:5} "
|
|
f"workers={cfg['workers']} timeout={timeout}s"
|
|
)
|
|
return 0
|
|
|
|
if not parsed.service:
|
|
parser.print_help()
|
|
return 1
|
|
|
|
cfg = get_service_config(parsed.service, "prod")
|
|
service_dir = workspace_root / cfg["dir"]
|
|
|
|
if not service_dir.exists():
|
|
print(f"Error: {service_dir} not found", file=sys.stderr)
|
|
return 1
|
|
|
|
# Set environment variables for production port
|
|
env = os.environ.copy()
|
|
if parsed.service == "coordinator":
|
|
env["MODEL_BOSS_PORT"] = str(cfg["port"])
|
|
elif parsed.service == "llama-http":
|
|
env["LLAMA_HTTP_PORT"] = str(cfg["port"])
|
|
|
|
# Use python -m to run the service module
|
|
cmd = ["python", "-m", cfg["module"]]
|
|
|
|
# For Python services, activate venv
|
|
venv = service_dir / ".venv/bin/activate"
|
|
if venv.exists():
|
|
# Pass environment variables through bash
|
|
env_exports = " ".join(f"{k}={v}" for k, v in env.items() if k.startswith(("MODEL_BOSS_", "LLAMA_HTTP_")))
|
|
full_cmd = f"source {venv} && {env_exports} {' '.join(cmd)}"
|
|
cmd = ["bash", "-c", full_cmd]
|
|
|
|
print(f"Starting {parsed.service} (production) on port {cfg['port']}")
|
|
print(f"Workers: {parsed.workers or cfg['workers']}")
|
|
print(f"Timeout: {cfg['timeout_keep_alive']}s")
|
|
print()
|
|
|
|
try:
|
|
return subprocess.run(cmd, cwd=service_dir, env=env).returncode
|
|
except KeyboardInterrupt:
|
|
return 0
|
|
|
|
|
|
def register_prod_command(runner):
|
|
"""Register the prod command with the script runner.
|
|
|
|
Args:
|
|
runner: ScriptRunner instance
|
|
"""
|
|
runner.register_command(
|
|
"prod",
|
|
prod_command,
|
|
"Start production servers",
|
|
)
|