Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
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()
|
|
print("stop crash loop", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c 'systemctl stop douyinweb-web; systemctl reset-failed douyinweb-web; "
|
|
"ls -la /opt/douyinWEB/frontend/.next 2>&1 | head -5; "
|
|
"rm -f /tmp/fe-net2.log'",
|
|
30,
|
|
),
|
|
flush=True,
|
|
)
|
|
# rebuild sync with long timeout — reconnect-safe via nohup + poll
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c '"
|
|
"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-net2.log 2>&1 & echo PID=$!'"
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
for i in range(50):
|
|
time.sleep(12)
|
|
g = ssh()
|
|
st = run(
|
|
g,
|
|
"tail -n 4 /tmp/fe-net2.log 2>/dev/null; "
|
|
"test -f /opt/douyinWEB/frontend/.next/BUILD_ID && echo HAS_BUILD || echo NO_BUILD; "
|
|
"pgrep -af 'next build|npm run build' >/dev/null && echo BUILDING || echo IDLE",
|
|
20,
|
|
)
|
|
g.close()
|
|
print(f"[{i}] {st.strip()[-280:]}", flush=True)
|
|
if "HAS_BUILD" in st and "IDLE" in st:
|
|
# ensure log finished
|
|
g = ssh()
|
|
log_end = run(g, "tail -n 8 /tmp/fe-net2.log")
|
|
g.close()
|
|
if "Compiled successfully" in log_end or "✓" in log_end or "Route (app)" in log_end or "HAS_BUILD" in st:
|
|
break
|
|
if "IDLE" in st and "NO_BUILD" in st and i > 3:
|
|
g = ssh()
|
|
print("FAIL LOG", run(g, "tail -n 60 /tmp/fe-net2.log"), flush=True)
|
|
g.close()
|
|
raise SystemExit("build failed")
|
|
else:
|
|
raise SystemExit("build timeout")
|
|
|
|
g = ssh()
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c '"
|
|
"systemctl start douyinweb-web; sleep 3; systemctl is-active douyinweb-web; "
|
|
"curl -sS -m 5 -o /dev/null -w local_network:%{http_code}\\\\n http://127.0.0.1:4015/network; "
|
|
"cat /opt/douyinWEB/frontend/.next/BUILD_ID'"
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
with httpx.Client(timeout=20.0) as client:
|
|
print("public_network", client.get("https://dy.nomadro.com/network", follow_redirects=False).status_code, flush=True)
|
|
print("dylive", client.get("https://dylive.nomadro.com/api/health").status_code, flush=True)
|
|
print("DONE", flush=True)
|