douyinWEB/scripts/_snap_physical_polish.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

103 lines
3.7 KiB
Python

# -*- coding: utf-8 -*-
"""Snapshot physical guest + VPS edge health for polish pass."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(port, user, pw):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(
"107.173.30.245",
port,
user,
pw,
timeout=45,
banner_timeout=90,
allow_agent=False,
look_for_keys=False,
)
return c
except Exception as ex:
print("ssh", port, i, type(ex).__name__, flush=True)
time.sleep(2)
raise RuntimeError(f"ssh {port}")
def run(c, cmd, timeout=60):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
g = ssh(4014, "eric", "4669805")
print("=== GUEST ===", flush=True)
print(
run(
g,
"echo '4669805' | sudo -S -p '' bash -lc '"
"echo --- units ---; "
"systemctl is-active douyinweb-api douyinweb-web douyinweb-pb douyinweb-yt douyinweb-s3 docker wg-quick@wg-dy 2>/dev/null; "
"echo --- listen ---; "
"ss -lntp | grep -E \":(4015|8014|8092|8333|9200|52300)\\b\" || true; "
"echo --- wg ---; "
"ip -br a show wg-dy; wg show wg-dy 2>/dev/null | head -20; "
"echo --- neko ---; "
"docker ps --filter name=douyinweb-neko --format \"{{.Names}} {{.Status}} {{.Ports}}\" || true; "
"echo --- env ---; "
"grep -E \"DY_(PUBLIC|INTERNAL|NEKO|SESSION|CORS)\" /etc/systemd/system/douyinweb-api.service || true; "
"echo --- TimeoutStop ---; "
"systemctl show douyinweb-api -p TimeoutStopUSec -p TimeoutStartUSec -p KillMode 2>/dev/null; "
"echo --- data hygiene ---; "
"python3 - <<\"PY\"\n"
"import sqlite3\n"
"from pathlib import Path\n"
"db=Path(\"/opt/douyinWEB/backend/data/monitor.db\")\n"
"print(\"db_exists\", db.is_file(), \"size\", db.stat().st_size if db.is_file() else 0)\n"
"if db.is_file():\n"
" con=sqlite3.connect(db)\n"
" try:\n"
" print(\"rooms\", con.execute(\"select count(*) from rooms\").fetchone()[0])\n"
" except Exception as e:\n"
" print(\"rooms_err\", e)\n"
" con.close()\n"
"print(\"socks_profiles_file\", Path(\"/opt/douyinWEB/backend/data/wireguard/imports\").exists())\n"
"PY\n"
"ls /opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Extensions 2>/dev/null | head -3 || echo NO_SEED; "
"echo --- disk ---; "
"df -h / /opt 2>/dev/null | tail -n +1; "
"echo --- api health ---; "
"curl -sS -m 5 -o /dev/null -w \"%{http_code}\" http://127.0.0.1:8014/api/health; echo"
"'",
90,
),
flush=True,
)
g.close()
v = ssh(22, "root", "Xiao4669805")
print("=== VPS EDGE ===", flush=True)
print(
run(
v,
"curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health; "
"curl -sS -m 8 -o /dev/null -w 'dy_api:%{http_code}\\n' https://dy.nomadro.com/api/health; "
"curl -sS -m 8 -o /dev/null -w 'dy_network:%{http_code}\\n' https://dy.nomadro.com/network; "
"curl -sS -m 8 -o /dev/null -w 'dy_neko1:%{http_code}\\n' https://dy.nomadro.com/neko/1/; "
"curl -sS -m 5 -o /dev/null -w 'wg_ping:%{http_code}\\n' http://10.8.0.2:8014/api/health; "
"grep -n neko /etc/caddy/sites/dy.nomadro.com.caddy | head -8; "
"ping -c 1 -W 2 10.8.0.2 | tail -2",
40,
),
flush=True,
)
v.close()
print("DONE", flush=True)