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>
128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy host-side Studio CDP poller + minute-report persistence.
|
|
|
|
API restart only. NEVER restart Chrome / NEVER recreate Neko.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
PASS = "4669805"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
FILES = [
|
|
("backend/app/youtube_neko.py", "/tmp/_cdp_poll_neko.py"),
|
|
("backend/app/main.py", "/tmp/_cdp_poll_main.py"),
|
|
("backend/neko/cdp_studio_scrape.py", "/tmp/_cdp_poll_scrape.py"),
|
|
("frontend/src/components/YouTubeLiveTicker.tsx", "/tmp/_cdp_poll_ticker.tsx"),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
install -m 644 /tmp/_cdp_poll_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
install -m 644 /tmp/_cdp_poll_main.py /opt/douyinWEB/backend/app/main.py
|
|
install -m 644 /tmp/_cdp_poll_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
|
|
install -m 644 /tmp/_cdp_poll_ticker.tsx /opt/douyinWEB/frontend/src/components/YouTubeLiveTicker.tsx
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python -m py_compile app/youtube_neko.py app/main.py
|
|
|
|
BEFORE=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
# API only — do not touch Chrome / Neko containers
|
|
systemctl restart douyinweb-api
|
|
sleep 5
|
|
systemctl is-active douyinweb-api
|
|
AFTER=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_BEFORE=$BEFORE NEKO_AFTER=$AFTER"
|
|
test "$BEFORE" = "$AFTER"
|
|
|
|
# Frontend ticker dedupe (Next rebuild)
|
|
systemctl stop douyinweb-web || true
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-web
|
|
|
|
echo SMOKE_POLL
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
import json
|
|
from app import youtube_neko as yn
|
|
out = yn.poll_studio_cdp_once()
|
|
print(json.dumps(out, ensure_ascii=False)[:2500])
|
|
print("--- minute samples ---")
|
|
for nid in range(1, 8):
|
|
rows = yn.list_studio_minute_reports(nid, limit=2)
|
|
if rows:
|
|
r = rows[0]
|
|
print(f"neko{nid}", "on_air", r.get("on_air"), "viewers", r.get("viewer_count"), "src", r.get("source"), "status", r.get("live_status"))
|
|
PY
|
|
|
|
echo LIVE_MAP
|
|
curl -sS -m 25 'http://127.0.0.1:8014/api/youtube/live-map' -o /tmp/_live_map.json
|
|
.venv/bin/python - <<'PY'
|
|
import json
|
|
from pathlib import Path
|
|
raw = Path("/tmp/_live_map.json").read_text(encoding="utf-8")
|
|
d = json.loads(raw)
|
|
print("live_count", d.get("live_count"))
|
|
ents = d.get("entries") or {}
|
|
for k, v in sorted(ents.items()):
|
|
if v.get("is_live"):
|
|
print(k, "src", v.get("source"), "title", (v.get("title") or "")[:40])
|
|
PY
|
|
|
|
echo DEPLOY_OK
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(12):
|
|
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)
|
|
else:
|
|
return 1
|
|
|
|
sftp = c.open_sftp()
|
|
for rel, tmp in FILES:
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write((ROOT / rel).read_bytes())
|
|
print("up", rel, flush=True)
|
|
with sftp.file("/tmp/_cdp_poll_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
|
|
_, o, e = c.exec_command(
|
|
f"echo '{PASS}' | sudo -S -p '' bash /tmp/_cdp_poll_deploy.sh",
|
|
timeout=900,
|
|
)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-12000:] if len(out) > 12000 else out)
|
|
c.close()
|
|
return 0 if "DEPLOY_OK" in out else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|