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>
210 lines
7.0 KiB
Python
210 lines
7.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Non-destructive physical deploy: live-map + Neko studio feedback.
|
|
|
|
Does NOT:
|
|
- docker compose recreate / force-recreate
|
|
- stop/restart Neko containers
|
|
- restart Chrome inside Neko
|
|
- touch profiles / cookies / tabs
|
|
|
|
Does:
|
|
- update API + frontend + extension bind-mount files
|
|
- restart douyinweb-api + rebuild web only
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
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]
|
|
PASS = "4669805"
|
|
|
|
FILES = [
|
|
("backend/app/youtube_live.py", "/opt/douyinWEB/backend/app/youtube_live.py", "_nd_youtube_live.py"),
|
|
("backend/app/youtube_neko.py", "/opt/douyinWEB/backend/app/youtube_neko.py", "_nd_youtube_neko.py"),
|
|
(
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"/opt/douyinWEB/backend/app/youtube_relay_pipeline.py",
|
|
"_nd_pipeline.py",
|
|
),
|
|
("frontend/src/app/page.tsx", "/opt/douyinWEB/frontend/src/app/page.tsx", "_nd_page.tsx"),
|
|
(
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"/opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"_nd_pro.tsx",
|
|
),
|
|
(
|
|
"frontend/src/lib/ytRelayStatus.ts",
|
|
"/opt/douyinWEB/frontend/src/lib/ytRelayStatus.ts",
|
|
"_nd_ytRelayStatus.ts",
|
|
),
|
|
(
|
|
"backend/neko/live-ops-extension/background.js",
|
|
"/opt/douyinWEB/backend/neko/live-ops-extension/background.js",
|
|
"_nd_ext_bg.js",
|
|
),
|
|
(
|
|
"backend/neko/live-ops-extension/content.js",
|
|
"/opt/douyinWEB/backend/neko/live-ops-extension/content.js",
|
|
"_nd_ext_ct.js",
|
|
),
|
|
(
|
|
"backend/neko/live-ops-extension/manifest.json",
|
|
"/opt/douyinWEB/backend/neko/live-ops-extension/manifest.json",
|
|
"_nd_ext_mf.json",
|
|
),
|
|
(
|
|
"backend/neko/live-ops-extension/instance_id.txt",
|
|
"/opt/douyinWEB/backend/neko/live-ops-extension/instance_id.txt",
|
|
"_nd_ext_id.txt",
|
|
),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
TS=$(date +%s)
|
|
ins(){ cp -a "$2" "$2.bak-nd-$TS" 2>/dev/null || true; install -m 644 "$1" "$2"; }
|
|
echo "=== install files (no docker / no chrome) ==="
|
|
ins /tmp/_nd_youtube_live.py /opt/douyinWEB/backend/app/youtube_live.py
|
|
ins /tmp/_nd_youtube_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
ins /tmp/_nd_pipeline.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
ins /tmp/_nd_page.tsx /opt/douyinWEB/frontend/src/app/page.tsx
|
|
ins /tmp/_nd_pro.tsx /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx
|
|
ins /tmp/_nd_ytRelayStatus.ts /opt/douyinWEB/frontend/src/lib/ytRelayStatus.ts
|
|
ins /tmp/_nd_ext_bg.js /opt/douyinWEB/backend/neko/live-ops-extension/background.js
|
|
ins /tmp/_nd_ext_ct.js /opt/douyinWEB/backend/neko/live-ops-extension/content.js
|
|
ins /tmp/_nd_ext_mf.json /opt/douyinWEB/backend/neko/live-ops-extension/manifest.json
|
|
ins /tmp/_nd_ext_id.txt /opt/douyinWEB/backend/neko/live-ops-extension/instance_id.txt
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python -m py_compile app/youtube_live.py app/youtube_neko.py app/youtube_relay_pipeline.py
|
|
echo COMPILE_OK
|
|
|
|
# Snapshot running Nekos BEFORE any service restart (must stay up).
|
|
echo "=== neko running (must remain) ==="
|
|
docker ps --filter name=douyinweb-neko- --format '{{.Names}} {{.Status}}' || true
|
|
NEKO_BEFORE=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_BEFORE=$NEKO_BEFORE"
|
|
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
|
|
systemctl stop douyinweb-web || true
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-web
|
|
echo BUILD_OK
|
|
|
|
NEKO_AFTER=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_AFTER=$NEKO_AFTER"
|
|
if [ "$NEKO_BEFORE" != "$NEKO_AFTER" ]; then
|
|
echo "WARN_NEKO_COUNT_CHANGED before=$NEKO_BEFORE after=$NEKO_AFTER"
|
|
else
|
|
echo NEKO_STABLE_OK
|
|
fi
|
|
|
|
# Explicitly do NOT touch compose / chrome
|
|
echo "SKIP_DOCKER_RECREATE=1"
|
|
echo "SKIP_CHROME_RESTART=1"
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2 + i)
|
|
else:
|
|
raise SystemExit("ssh fail")
|
|
|
|
sftp = c.open_sftp()
|
|
for rel, _dst, tmp in FILES:
|
|
data = (ROOT / rel).read_bytes()
|
|
with sftp.file(f"/tmp/{tmp}", "wb") as f:
|
|
f.write(data)
|
|
print("up", rel, flush=True)
|
|
with sftp.file("/tmp/_nd_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_nd_deploy.sh", timeout=1200)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-16000:] if len(out) > 16000 else out, flush=True)
|
|
c.close()
|
|
|
|
if "COMPILE_OK" not in out or "BUILD_OK" not in out:
|
|
return 1
|
|
if "NEKO_STABLE_OK" not in out and "WARN_NEKO_COUNT_CHANGED" in out:
|
|
print("neko count changed — investigate", flush=True)
|
|
return 2
|
|
|
|
# Probe public health + force live-map via loopback through guest is harder without cookie.
|
|
for url in ("https://dy.nomadro.com/api/health", "https://dy.nomadro.cn/api/health"):
|
|
try:
|
|
r = httpx.get(url, timeout=20)
|
|
print(url, r.status_code, flush=True)
|
|
except Exception as ex:
|
|
print(url, ex, flush=True)
|
|
|
|
# Guest-side live-map probe (localhost, may need auth cookie — best-effort)
|
|
c2 = paramiko.SSHClient()
|
|
c2.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c2.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
probe = r"""
|
|
python3 - <<'PY'
|
|
import json, urllib.request
|
|
try:
|
|
req = urllib.request.Request('http://127.0.0.1:8014/api/youtube/live-map?force=1')
|
|
with urllib.request.urlopen(req, timeout=60) as r:
|
|
body = r.read().decode()
|
|
data = json.loads(body)
|
|
entries = data.get('entries') or {}
|
|
live = {k:v for k,v in entries.items() if isinstance(v, dict) and v.get('is_live') and (k.startswith('assign:') or k.startswith('shorts:'))}
|
|
print('live_count', data.get('live_count'))
|
|
print('live_keys', sorted(live.keys())[:20])
|
|
for k,v in sorted(live.items())[:8]:
|
|
print(k, 'src=', v.get('source'), 'title=', (v.get('title') or '')[:40])
|
|
except Exception as e:
|
|
print('probe_err', type(e).__name__, e)
|
|
PY
|
|
"""
|
|
_, o2, e2 = c2.exec_command(probe, timeout=90)
|
|
print((o2.read() + e2.read()).decode("utf-8", "replace"), flush=True)
|
|
c2.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|