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>
133 lines
4.1 KiB
Python
133 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Patch HTTP bind to 0.0.0.0 on physical guest and recreate Neko #1."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
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"
|
|
|
|
RECREATE = 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.setdefault("DY_NEKO_EDGE_UPSTREAM", "10.8.0.2")
|
|
os.environ.setdefault("DY_NEKO_NAT1TO1", "107.173.30.245")
|
|
os.environ.setdefault("DY_PUBLIC_BASE_URL", "https://dy.nomadro.com")
|
|
from app import youtube_neko
|
|
print("bind", youtube_neko._http_bind())
|
|
# force rewrite compose + recreate
|
|
youtube_neko.ensure_capacity(1, start_instances={1}, reconcile_running=True)
|
|
print("state", youtube_neko._container_state(1))
|
|
print("caddy", youtube_neko.sync_caddy_neko_snippet(4))
|
|
"""
|
|
|
|
|
|
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} {type(ex).__name__}", flush=True)
|
|
time.sleep(2 + i)
|
|
raise last # type: ignore[misc]
|
|
|
|
|
|
def run(c, cmd, timeout=300):
|
|
_, 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()
|
|
sftp.put(str(ROOT / "backend/app/youtube_neko.py"), "/tmp/_up_youtube_neko.py")
|
|
sftp.put(str(ROOT / "backend/app/config.py"), "/tmp/_up_config.py")
|
|
with sftp.file("/tmp/_recreate_neko.py", "w") as f:
|
|
f.write(RECREATE)
|
|
sftp.close()
|
|
|
|
print("=== install + env ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc "
|
|
"'set -e; "
|
|
"install -m 644 /tmp/_up_youtube_neko.py /opt/douyinWEB/backend/app/youtube_neko.py; "
|
|
"install -m 644 /tmp/_up_config.py /opt/douyinWEB/backend/app/config.py; "
|
|
"grep -q DY_NEKO_HTTP_BIND /etc/systemd/system/douyinweb-api.service || "
|
|
" sed -i \"/DY_NEKO_NAT1TO1=/a Environment=DY_NEKO_HTTP_BIND=0.0.0.0\" /etc/systemd/system/douyinweb-api.service; "
|
|
"systemctl daemon-reload; "
|
|
"systemctl restart douyinweb-api; "
|
|
"sleep 3; systemctl is-active douyinweb-api'",
|
|
60,
|
|
),
|
|
flush=True,
|
|
)
|
|
|
|
print("=== recreate neko1 ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{GUEST_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("=== ports ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc "
|
|
"'docker ps --filter name=douyinweb-neko-1 --format \"{{.Ports}}\"; "
|
|
"ss -lntp | grep 9200; "
|
|
"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 wgself:%{{http_code}}\\\\n http://10.8.0.2:9200/'",
|
|
30,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
v = ssh(VPS, 22, "root", VPS_PW)
|
|
print(
|
|
run(
|
|
v,
|
|
"curl -sS -m 10 -o /dev/null -w 'wg_from_vps:%{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",
|
|
30,
|
|
),
|
|
flush=True,
|
|
)
|
|
v.close()
|
|
print("DONE", flush=True)
|