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>
102 lines
2.8 KiB
Python
102 lines
2.8 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"
|
|
PW = "4669805"
|
|
|
|
|
|
def ssh(port=4014, user="eric", password=PW):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(6):
|
|
try:
|
|
c.connect(VPS, port, user, password, timeout=45, banner_timeout=60, allow_agent=False, look_for_keys=False)
|
|
return c
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2)
|
|
raise RuntimeError("ssh fail")
|
|
|
|
|
|
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()
|
|
print("=== force api ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c '"
|
|
"systemctl kill -s SIGKILL douyinweb-api || true; "
|
|
"sleep 1; "
|
|
"systemctl reset-failed douyinweb-api || true; "
|
|
"systemctl start douyinweb-api; "
|
|
"sleep 2; "
|
|
"systemctl is-active douyinweb-api; "
|
|
"ss -lntp | grep 8014 || true"
|
|
"'",
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
for i in range(10):
|
|
time.sleep(3)
|
|
st = run(g, "curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x", 15)
|
|
print(f"health {i} {st.strip()}", flush=True)
|
|
if "200" in st:
|
|
break
|
|
|
|
print("=== recreate neko ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' "
|
|
"env DY_NEKO_HTTP_BIND=0.0.0.0 DY_NEKO_EDGE_UPSTREAM=10.8.0.2 "
|
|
"DY_NEKO_NAT1TO1=107.173.30.245 DY_PUBLIC_BASE_URL=https://dy.nomadro.com "
|
|
"/opt/douyinWEB/backend/.venv/bin/python /tmp/_recreate_neko.py",
|
|
300,
|
|
),
|
|
flush=True,
|
|
)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' docker ps --filter name=douyinweb-neko-1 --format '{{{{.Status}}}} {{{{.Ports}}}}'",
|
|
20,
|
|
),
|
|
flush=True,
|
|
)
|
|
print(
|
|
run(
|
|
g,
|
|
"curl -sS -m 5 -o /dev/null -w 'loop:%{http_code}\n' http://127.0.0.1:9200/; "
|
|
"curl -sS -m 5 -o /dev/null -w 'wg:%{http_code}\n' http://10.8.0.2:9200/",
|
|
20,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
v = ssh(22, "root", "Xiao4669805")
|
|
print(
|
|
run(
|
|
v,
|
|
"curl -sS -m 10 -o /dev/null -w 'vps_wg:%{http_code}\n' http://10.8.0.2:9200/; "
|
|
"curl -sS -m 10 -o /dev/null -w 'neko1:%{http_code}\n' https://dy.nomadro.com/neko/1/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'network:%{http_code}\n' https://dy.nomadro.com/network; "
|
|
"curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\n' https://dylive.nomadro.com/api/health",
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
v.close()
|
|
print("DONE", flush=True)
|