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>
117 lines
3.3 KiB
Python
117 lines
3.3 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")
|
|
|
|
|
|
def run(c, cmd, timeout=120):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
g = ssh()
|
|
print("wait removal...", flush=True)
|
|
time.sleep(8)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{PW}' | sudo -S -p '' bash -c '"
|
|
"docker rm -f douyinweb-neko-1 2>/dev/null || true; "
|
|
"sleep 2; "
|
|
"docker ps -a --filter name=douyinweb-neko-1; "
|
|
"grep -n \"9200:8080\" /opt/douyinWEB/backend/data/neko/docker-compose.yml | head'"
|
|
"'",
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
|
|
UP = r"""
|
|
import os, sys
|
|
sys.path.insert(0, "/opt/douyinWEB/backend")
|
|
os.chdir("/opt/douyinWEB/backend")
|
|
os.environ["DY_NEKO_HTTP_BIND"] = "0.0.0.0"
|
|
os.environ["DY_NEKO_EDGE_UPSTREAM"] = "10.8.0.2"
|
|
os.environ["DY_NEKO_NAT1TO1"] = "107.173.30.245"
|
|
os.environ["DY_PUBLIC_BASE_URL"] = "https://dy.nomadro.com"
|
|
from app import youtube_neko
|
|
# ensure compose has 0.0.0.0 bind
|
|
text = youtube_neko._render_compose(1)
|
|
youtube_neko._compose_path().write_text(text, encoding="utf-8")
|
|
print("compose_bind_line", [ln for ln in text.splitlines() if "9200:8080" in ln])
|
|
r = youtube_neko.ensure_capacity(1, start_instances={1}, reconcile_running=True)
|
|
print("ensure", r)
|
|
print("state", youtube_neko._container_state(1))
|
|
"""
|
|
sftp = g.open_sftp()
|
|
with sftp.file("/tmp/_up_neko_again.py", "w") as f:
|
|
f.write(UP)
|
|
sftp.close()
|
|
|
|
print("=== up again ===", 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/_up_neko_again.py",
|
|
300,
|
|
),
|
|
flush=True,
|
|
)
|
|
time.sleep(5)
|
|
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 8 -o /dev/null -w 'loop:%{http_code}\n' http://127.0.0.1:9200/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'wg:%{http_code}\n' http://10.8.0.2:9200/",
|
|
25,
|
|
),
|
|
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)
|