douyinWEB/scripts/_verify_dy_nomadro_edge.py
2026-09-13 22:10:49 -05:00

99 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Verify dy.nomadro.com path is intact; ensure edge deps stay up."""
from __future__ import annotations
import sys
import time
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def connect():
last = None
for i in range(12):
try:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=60,
banner_timeout=180,
allow_agent=False,
look_for_keys=False,
)
print("connected", i, flush=True)
return c
except Exception as ex:
last = ex
print("retry", i, type(ex).__name__, ex, flush=True)
time.sleep(5)
raise SystemExit(f"ssh failed: {last}")
def run(c, cmd, t=90):
print(f"\n$ {cmd[:240]}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
code = o.channel.recv_exit_status()
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-7000:] if len(out) > 7000 else out, flush=True)
return code, out
def main() -> int:
print("=== public probes ===", flush=True)
with httpx.Client(follow_redirects=False, timeout=25, verify=True) as cl:
for url in [
"https://dy.nomadro.com/",
"https://dy.nomadro.com/api/health",
"https://dy.nomadro.com/login",
"https://dylive.nomadro.com/api/health",
]:
try:
r = cl.get(url)
loc = r.headers.get("location", "")
print(f"{url} -> {r.status_code} loc={loc[:80]}", flush=True)
except Exception as ex:
print(f"{url} ERR {ex}", flush=True)
c = connect()
try:
# Ensure physical edge deps are running (do NOT touch stopped product stacks)
run(
c,
"systemctl start caddy nginx 'wg-quick@wg-dy' frpp docker 2>/dev/null; "
"systemctl is-active caddy nginx 'wg-quick@wg-dy' frpp docker douyinweb-api douyinweb-web; "
"wg show wg-dy 2>/dev/null | head -20",
60,
)
run(
c,
"grep -Rne 'dy.nomadro.com\\|10.8.0.2' /etc/caddy /etc/caddy/Caddyfile* 2>/dev/null | head -40; "
"ls /etc/caddy 2>/dev/null; "
"curl -sS -m 10 -o /dev/null -w 'via_wg=%{http_code}\\n' http://10.8.0.2:8014/api/health || echo via_wg_fail; "
"curl -sS -m 10 -o /dev/null -w 'via_wg_web=%{http_code}\\n' http://10.8.0.2:4015/ || echo via_wg_web_fail",
40,
)
# Confirm product nomadro units stay stopped (unrelated to dy.nomadro.com)
run(
c,
"echo 'product nomadro (should stay stopped):'; "
"for u in nomadro nomadro-api nomadro-web nomadro-router nomadro-live-router; do "
" printf '%s %s\\n' $u $(systemctl is-active $u 2>/dev/null); "
"done",
30,
)
print("\nDONE", flush=True)
return 0
finally:
c.close()
if __name__ == "__main__":
raise SystemExit(main())