# -*- coding: utf-8 -*- """Recover stuck douyinweb-api restart — no db changes.""" import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd: str, timeout: int = 120) -> str: print("$", cmd[:180]) _s, out, err = c.exec_command(cmd, timeout=timeout) o = out.read().decode("utf-8", "replace").strip() e = err.read().decode("utf-8", "replace").strip() if o: print(o) if e: print("ERR:", e[:600]) return o run("systemctl is-active douyinweb-api") run("systemctl kill -s SIGKILL douyinweb-api 2>/dev/null; sleep 2; systemctl reset-failed douyinweb-api 2>/dev/null; systemctl start douyinweb-api") time.sleep(12) run("systemctl is-active douyinweb-api") run("curl -sS http://127.0.0.1:8014/api/health") run("curl -sS http://127.0.0.1:8014/api/monitor/status | head -c 300") run("curl -sS http://127.0.0.1:8014/api/shorts/status | head -c 300") run("curl -sS http://127.0.0.1:8014/api/tiktok/setup | head -c 400") print("\n=== frontend build (tiktok page) ===") run("cd /opt/douyinWEB/frontend && npm run build 2>&1 | tail -6", timeout=420) c.exec_command("systemctl restart douyinweb-web", timeout=5) time.sleep(8) run("systemctl is-active douyinweb-web") c.close() print("RECOVERED")