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

113 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""Push fixed wireguard_watch.sh and re-verify checklist."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
VPS = "107.173.30.245"
GUEST_PW = "4669805"
VPS_PW = "Xiao4669805"
PVE_WG = "10.8.0.2"
def ssh(port, user, password, tries=6):
last = None
for i in range(tries):
try:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
VPS, port, user, password,
timeout=40, banner_timeout=80,
allow_agent=False, look_for_keys=False,
)
return c
except Exception as ex:
last = ex
print(f"ssh:{port} fail{i} {type(ex).__name__}", flush=True)
time.sleep(2 + i)
raise last # type: ignore[misc]
def run(c, cmd, timeout=90):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
def main() -> int:
g = ssh(4014, "eric", GUEST_PW)
sftp = g.open_sftp()
data = (ROOT / "scripts/linux/wireguard_watch.sh").read_bytes()
data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
with sftp.file("/tmp/_up_wireguard_watch.sh", "wb") as f:
f.write(data)
sftp.close()
print(
run(
g,
f"echo '{GUEST_PW}' | sudo -S -p '' bash -c '"
"install -m 755 /tmp/_up_wireguard_watch.sh /opt/douyinWEB/scripts/linux/wireguard_watch.sh; "
"systemctl reset-failed douyinweb-wireguard-watch || true; "
"systemctl restart douyinweb-wireguard-watch; "
"sleep 3; "
"systemctl is-active douyinweb-wireguard-watch; "
"systemctl show douyinweb-wireguard-watch -p ActiveState -p SubState -p MainPID --no-pager; "
"journalctl -u douyinweb-wireguard-watch -n 8 --no-pager'"
),
flush=True,
)
g.close()
print("=== SSH over WG ===", flush=True)
try:
v = ssh(22, "root", VPS_PW, tries=4)
print(
run(
v,
f"sshpass -p '{GUEST_PW}' ssh -o StrictHostKeyChecking=no -o ConnectTimeout=8 "
f"eric@{PVE_WG} 'hostname; systemctl is-active douyinweb-wireguard-watch'; "
"curl -sS -m 8 -o /dev/null -w via_wg:%{http_code}\\\\n http://10.8.0.2:8014/api/health; "
"curl -sS -m 8 -o /dev/null -w dylive:%{http_code}\\\\n https://dylive.nomadro.com/api/health",
),
flush=True,
)
v.close()
except Exception as ex:
print(f"vps skip {type(ex).__name__}", flush=True)
with httpx.Client(base_url="https://dy.nomadro.com", timeout=25.0, follow_redirects=False) as client:
client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"})
j = client.get("/api/network").json()
roles = j.get("path_roles") or {}
print("policy", roles.get("policy"), flush=True)
print("app", roles.get("app_https"), flush=True)
print("ssh", roles.get("ops_ssh"), flush=True)
wg = j.get("wireguard") or {}
frp = j.get("frp") or {}
print(
"wg", wg.get("role"), "fresh", wg.get("handshake_fresh"),
"age", wg.get("handshake_age_sec"),
"watch", (wg.get("watch") or {}).get("unit"),
flush=True,
)
print("frp", frp.get("role"), frp.get("purpose"), flush=True)
cl = j.get("physical_checklist") or {}
print("ok=", cl.get("ok"), "failed=", cl.get("failed"), flush=True)
for c in cl.get("checks") or []:
print(f" [{'OK' if c.get('ok') else '!!'}] {c.get('name')}: {c.get('detail')}", flush=True)
print("page", client.get("/network").status_code, flush=True)
print("DONE", flush=True)
return 0
if __name__ == "__main__":
raise SystemExit(main())