#!/usr/bin/env python3 """Restart both AO3 workers manually.""" import subprocess, time, os BASE_DIR = "/home/ubuntu/ao3-mirror" SHM_DIR = "/dev/shm/ao3" VENV = "/home/ubuntu/.hermes/hermes-agent/venv/bin/python3" os.makedirs(SHM_DIR, exist_ok=True) for i, port in [(0, 8081), (1, 8082)]: log = f"{BASE_DIR}/worker-{i}.log" proc = subprocess.Popen( ["taskset", "-c", str(i), VENV, "-m", "uvicorn", "app:app", "--host", "127.0.0.1", "--port", str(port), "--workers", "1", "--loop", "uvloop", "--http", "httptools", "--log-level", "warning", "--timeout-keep-alive", "30"], cwd=BASE_DIR, stdout=open(log, "a"), stderr=open(log, "a"), ) pid_file = f"{SHM_DIR}/worker-{i}.pid" with open(pid_file, "w") as f: f.write(str(proc.pid)) print(f"Worker {i} port {port} started PID={proc.pid}") time.sleep(2) print("Both workers started")