# -*- coding: utf-8 -*- from __future__ import annotations import sys import time from pathlib import Path import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] PW = "4669805" def ssh(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(6): try: c.connect("107.173.30.245", 4014, "eric", PW, timeout=45, banner_timeout=90, allow_agent=False, look_for_keys=False) return c except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2) raise RuntimeError("ssh") def run(c, cmd, timeout=120): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace") g = ssh() sftp = g.open_sftp() sftp.put(str(ROOT / "frontend/src/app/network/page.tsx"), "/tmp/_up_page.tsx") sftp.close() print( run( g, f"echo '{PW}' | sudo -S -p '' bash -c '" "install -m 644 /tmp/_up_page.tsx /opt/douyinWEB/frontend/src/app/network/page.tsx; " "systemctl stop douyinweb-web || true; " "pkill -f \"next build\" || true; " "rm -f /tmp/fe-net3.log; " "cd /opt/douyinWEB/frontend; " "export DY_INTERNAL_API_URL=http://127.0.0.1:8014 DY_PUBLIC_BASE_URL=https://dy.nomadro.com; " "nohup npm run build >/tmp/fe-net3.log 2>&1 & echo STARTED'" ), flush=True, ) g.close() for i in range(45): time.sleep(12) g = ssh() st = run( g, "tail -n 3 /tmp/fe-net3.log; " "test -f /opt/douyinWEB/frontend/.next/BUILD_ID && echo HAS_BUILD || echo NO_BUILD; " "grep -q 'Failed to compile' /tmp/fe-net3.log && echo FAIL || true; " "pgrep -af 'next build' >/dev/null && echo BUILDING || echo IDLE", 20, ) g.close() print(f"[{i}] {st.strip()[-220:]}", flush=True) if "FAIL" in st and "IDLE" in st: g = ssh() print(run(g, "grep -nE 'Type error|Error|Failed' /tmp/fe-net3.log | head -20"), flush=True) g.close() raise SystemExit("compile fail") if "HAS_BUILD" in st and "IDLE" in st: break else: raise SystemExit("timeout") g = ssh() print( run( g, f"echo '{PW}' | sudo -S -p '' bash -c '" "systemctl reset-failed douyinweb-web; systemctl start douyinweb-web; sleep 3; " "systemctl is-active douyinweb-web; " "curl -sS -m 5 -o /dev/null -w local:%{http_code}\\\\n http://127.0.0.1:4015/network'" ), flush=True, ) g.close() with httpx.Client(timeout=20.0, follow_redirects=False) as client: print("public", client.get("https://dy.nomadro.com/network").status_code, flush=True) print("dylive", client.get("https://dylive.nomadro.com/api/health").status_code, flush=True) print("DONE", flush=True)