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>
133 lines
4.3 KiB
Python
133 lines
4.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Diagnose dy.nomadro.com 502: Caddy → WG → physical guest services."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
OVERSEAS = ("107.173.30.245", 22, "root", "Xiao4669805")
|
|
GUEST = ("107.173.30.245", 4014, "eric", "4669805")
|
|
PASS_GUEST = "4669805"
|
|
|
|
|
|
def ssh(host, port, user, pw, tries=8):
|
|
last = None
|
|
for i in range(tries):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
host,
|
|
port,
|
|
user,
|
|
pw,
|
|
timeout=45,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"ssh {host}:{port} try{i} {type(ex).__name__}: {ex}", flush=True)
|
|
time.sleep(2)
|
|
raise SystemExit(f"ssh failed: {last}")
|
|
|
|
|
|
def run(c, cmd, timeout=60):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def main() -> int:
|
|
print("=== public curl ===", flush=True)
|
|
import urllib.request
|
|
|
|
for url in [
|
|
"https://dy.nomadro.com/api/health",
|
|
"https://dy.nomadro.com/",
|
|
"https://dylive.nomadro.com/api/health",
|
|
"https://dy.nomadro.cn/api/health",
|
|
]:
|
|
try:
|
|
req = urllib.request.Request(url, method="GET")
|
|
with urllib.request.urlopen(req, timeout=20) as r:
|
|
print(url, r.status, (r.read()[:120]).decode("utf-8", "replace"), flush=True)
|
|
except Exception as ex:
|
|
code = getattr(ex, "code", None)
|
|
print(url, "ERR", code or type(ex).__name__, str(ex)[:160], flush=True)
|
|
|
|
print("\n=== overseas VPS ===", flush=True)
|
|
v = ssh(*OVERSEAS)
|
|
print(run(v, "wg show wg-dy 2>/dev/null | head -n 30 || wg show | head -n 40"), flush=True)
|
|
print("--- ping 10.8.0.2 ---", flush=True)
|
|
print(run(v, "ping -c 2 -W 2 10.8.0.2 || true"), flush=True)
|
|
print("--- curl upstream ---", flush=True)
|
|
print(
|
|
run(
|
|
v,
|
|
"curl -sS -m 8 -o /dev/null -w 'web:%{http_code} t:%{time_total}\\n' http://10.8.0.2:4015/ ; "
|
|
"curl -sS -m 8 -o /dev/null -w 'api:%{http_code} t:%{time_total}\\n' http://10.8.0.2:8014/api/health ; "
|
|
"curl -sS -m 8 http://10.8.0.2:8014/api/health || true",
|
|
),
|
|
flush=True,
|
|
)
|
|
print("--- caddy dy site ---", flush=True)
|
|
print(
|
|
run(
|
|
v,
|
|
"grep -n 'dy.nomadro.com\\|10.8.0.2\\|4015\\|8014' /etc/caddy/Caddyfile /etc/caddy/*.caddy /etc/caddy/conf.d/* 2>/dev/null | head -n 80; "
|
|
"ls /etc/caddy 2>/dev/null; systemctl is-active caddy 2>/dev/null; "
|
|
"journalctl -u caddy --no-pager -n 25 2>/dev/null | tail -n 25",
|
|
),
|
|
flush=True,
|
|
)
|
|
v.close()
|
|
|
|
print("\n=== physical guest via FRP ===", flush=True)
|
|
try:
|
|
g = ssh(*GUEST)
|
|
except SystemExit as ex:
|
|
print("GUEST SSH FAILED", ex, flush=True)
|
|
return 1
|
|
|
|
print(
|
|
run(
|
|
g,
|
|
"echo HOST=$(hostname); uptime; "
|
|
"systemctl is-active douyinweb-api douyinweb-web 2>/dev/null; "
|
|
"ss -lntp 2>/dev/null | grep -E ':4015|:8014' || netstat -lntp 2>/dev/null | grep -E ':4015|:8014'; "
|
|
"curl -sS -m 5 -o /dev/null -w 'local_api:%{http_code}\\n' http://127.0.0.1:8014/api/health; "
|
|
"curl -sS -m 5 -o /dev/null -w 'local_web:%{http_code}\\n' http://127.0.0.1:4015/; "
|
|
"ip -br a | head -n 20; "
|
|
"ping -c 1 -W 2 10.8.0.1 || true",
|
|
),
|
|
flush=True,
|
|
)
|
|
print("--- recent api/web journal ---", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PASS_GUEST}' | sudo -S -p '' journalctl -u douyinweb-api -u douyinweb-web --no-pager -n 40 2>/dev/null | tail -n 40",
|
|
),
|
|
flush=True,
|
|
)
|
|
print("--- wg on guest ---", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PASS_GUEST}' | sudo -S -p '' bash -lc 'wg show 2>/dev/null | head -n 40; ip route | head -n 20'",
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|