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>
157 lines
4.5 KiB
Python
157 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Start Neko #1 on guest; verify HTTP; upload missing neko assets if needed."""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import sys
|
|
import tarfile
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
NEKO = ROOT / "backend" / "neko"
|
|
VPS = "107.173.30.245"
|
|
GUEST_PW = "4669805"
|
|
VPS_PW = "Xiao4669805"
|
|
|
|
|
|
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")
|
|
|
|
|
|
def sudo(cmd: str) -> str:
|
|
return f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc {repr(cmd)}"
|
|
|
|
|
|
# Pack non-seed neko assets (small)
|
|
buf = io.BytesIO()
|
|
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
|
for name in (
|
|
"browser-launch.sh",
|
|
"chromium.conf",
|
|
"google-chrome.conf",
|
|
"live-ops-extension",
|
|
"policies",
|
|
"provisioning",
|
|
"no-managed-policies",
|
|
"render_tampermonkey_provisioning.py",
|
|
):
|
|
p = NEKO / name
|
|
if p.exists():
|
|
tar.add(p, arcname=name)
|
|
print(f"pack {name}", flush=True)
|
|
buf.seek(0)
|
|
print(f"assets tar {len(buf.getvalue())/1024:.0f} KB", flush=True)
|
|
|
|
g = ssh(VPS, 4014, "eric", GUEST_PW)
|
|
sftp = g.open_sftp()
|
|
with sftp.file("/tmp/neko-assets.tar.gz", "wb") as f:
|
|
f.write(buf.getvalue())
|
|
with sftp.file("/tmp/_start_neko1.py", "w") as f:
|
|
f.write(
|
|
"import os\n"
|
|
"os.environ.setdefault('DY_NEKO_EDGE_UPSTREAM', '10.8.0.2')\n"
|
|
"os.environ.setdefault('DY_NEKO_NAT1TO1', '107.173.30.245')\n"
|
|
"os.environ.setdefault('DY_PUBLIC_BASE_URL', 'https://dy.nomadro.com')\n"
|
|
"from app import youtube_neko\n"
|
|
"print('assets', youtube_neko.status_summary(desired=1).get('assets'))\n"
|
|
"r = youtube_neko.instance_action(1, 'start')\n"
|
|
"print('start', r)\n"
|
|
"print('caddy', youtube_neko.sync_caddy_neko_snippet(4))\n"
|
|
)
|
|
sftp.close()
|
|
|
|
print("=== install assets ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
sudo(
|
|
"set -e; "
|
|
"mkdir -p /opt/douyinWEB/backend/neko; "
|
|
"tar -xzf /tmp/neko-assets.tar.gz -C /opt/douyinWEB/backend/neko; "
|
|
"ls /opt/douyinWEB/backend/neko | head -20; "
|
|
"test -f /opt/douyinWEB/backend/neko/browser-launch.sh && echo LAUNCH_OK; "
|
|
"test -d /opt/douyinWEB/backend/neko/tampermonkey-seed/Default && echo SEED_OK"
|
|
),
|
|
60,
|
|
),
|
|
flush=True,
|
|
)
|
|
|
|
print("=== start neko 1 (may take ~1-2min) ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
sudo(
|
|
"cd /opt/douyinWEB/backend; "
|
|
"export DY_NEKO_EDGE_UPSTREAM=10.8.0.2 DY_NEKO_NAT1TO1=107.173.30.245 "
|
|
"DY_PUBLIC_BASE_URL=https://dy.nomadro.com; "
|
|
".venv/bin/python /tmp/_start_neko1.py"
|
|
),
|
|
300,
|
|
),
|
|
flush=True,
|
|
)
|
|
|
|
print("=== local http ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
sudo(
|
|
"docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}} {{.Ports}}'; "
|
|
"curl -sS -m 8 -o /dev/null -w 'local9200:%{http_code}\\n' http://127.0.0.1:9200/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'wg9200:%{http_code}\\n' http://10.8.0.2:9200/ || true; "
|
|
"ss -lntp | grep -E '9200|52300' || true"
|
|
),
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
v = ssh(VPS, 22, "root", VPS_PW)
|
|
print("=== public ===", flush=True)
|
|
print(
|
|
run(
|
|
v,
|
|
"curl -sS -m 12 -o /dev/null -w 'neko1:%{http_code}\\n' https://dy.nomadro.com/neko/1/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'wg_direct:%{http_code}\\n' http://10.8.0.2:9200/; "
|
|
"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)
|