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

101 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
VPS = "107.173.30.245"
GUEST_PW = "4669805"
VPS_PW = "Xiao4669805"
REMOTE_PY = r"""
from app import youtube_neko, yt_assign_db, network_hub
groups = yt_assign_db.list_groups()
print("groups", len(groups))
print("sync", youtube_neko.sync_for_groups(groups))
print("caddy", youtube_neko.sync_caddy_neko_snippet(max(1, len(groups) or 4)))
print("neko_status", youtube_neko.status_summary())
snap = network_hub.snapshot() or {}
print("network_ok", bool(snap), "keys", sorted(snap.keys())[:25])
"""
def ssh(host, port, user, password, 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,
password,
timeout=60,
banner_timeout=90,
auth_timeout=60,
allow_agent=False,
look_for_keys=False,
)
return c
except Exception as ex:
last = ex
print(f"ssh fail{i} {host}:{port} {type(ex).__name__}", flush=True)
time.sleep(2 + i)
raise last # type: ignore[misc]
def run(c, cmd, timeout=180):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
g = ssh(VPS, 4014, "eric", GUEST_PW)
sftp = g.open_sftp()
with sftp.file("/tmp/_neko_sync.py", "w") as f:
f.write(REMOTE_PY)
sftp.close()
print(
run(
g,
f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc "
"'install -m 644 /tmp/_neko_sync.py /opt/douyinWEB/backend/_neko_sync.py; "
"cd /opt/douyinWEB/backend; .venv/bin/python _neko_sync.py; "
"rm -f _neko_sync.py'",
180,
),
flush=True,
)
print(
run(
g,
f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc "
"'head -n 40 /opt/douyinWEB/backend/data/neko/caddy-neko.snippet 2>/dev/null || echo NO_SNIPPET; "
"docker ps -a --filter name=douyinweb-neko --format \"{{.Names}} {{.Status}}\" || true'",
40,
),
flush=True,
)
g.close()
v = ssh(VPS, 22, "root", VPS_PW)
print(
run(
v,
"curl -sS -m 12 -o /dev/null -w 'dy_api:%{http_code}\\n' https://dy.nomadro.com/api/health; "
"curl -sS -m 12 -o /dev/null -w 'dy_network:%{http_code}\\n' https://dy.nomadro.com/network; "
"curl -sS -m 12 -o /dev/null -w 'dy_neko1:%{http_code}\\n' https://dy.nomadro.com/neko/1/; "
"curl -sS -m 12 http://10.8.0.2:8014/api/network | head -c 700; echo; "
"curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health; "
"grep -n neko /etc/caddy/sites/dy.nomadro.com.caddy | head",
40,
),
flush=True,
)
v.close()
print("DONE", flush=True)