douyinWEB/scripts/_snap_physical_now.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

56 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""Snapshot what is running on the physical Ubuntu guest (read-only)."""
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
p = paramiko.SSHClient()
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=25, allow_agent=False, look_for_keys=False)
v = paramiko.SSHClient()
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False)
def run(c, cmd, timeout=40):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
print("=== guest ===")
print(run(p, r"""echo '4669805' | sudo -S -p '' bash -c '
hostname; systemd-detect-virt
df -h / | tail -1
ip -4 addr show wg-dy 2>/dev/null | head -3
systemctl is-active wg-quick@wg-dy frpp ssh
echo --- units ---
systemctl is-active douyinweb-api douyinweb-web douyinweb-pb douyinweb-yt \
douyinweb-s3 douyinweb-sw-master douyinweb-sw-volume douyinweb-sw-filer 2>/dev/null
echo --- listen ---
ss -lntp | grep -E ":(4015|8014|8092|8020|8333)\b" || true
echo --- env ---
grep -E "^(DOMAIN|PUBLIC_BASE|WEB_PORT|API_PORT)=" /etc/douyinweb.env 2>/dev/null
echo --- rooms ---
/opt/douyinWEB/backend/.venv/bin/python - <<"PY"
import sqlite3
c=sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db")
print("rooms", c.execute("select count(*) from rooms").fetchone()[0])
PY
ls /opt/douyinWEB/frontend/src/app/covers/page.tsx 2>/dev/null && echo covers_page=yes
'"""))
print("=== vps side for physical ===")
print(run(v, r"""
wg show wg-dy 2>/dev/null | head -20
test -f /etc/caddy/sites/dy.nomadro.com.caddy && echo caddy_site=yes
curl -sS -m 8 -o /dev/null -w 'dy_api:%{http_code} dylive:%{http_code}\n' \
https://dy.nomadro.com/api/health https://dylive.nomadro.com/api/health
"""))
# fix dual -w
print(run(v, "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 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health"))
p.close()
v.close()