douyinWEB/scripts/_continue_neko_sh2b.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

76 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""Fix ingest reachability, upload browser-launch, build frontend hint, smoke API."""
from __future__ import annotations
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
REMOTE = r"""#!/bin/bash
set -e
# discover API bind
systemctl cat douyinweb-api | head -80
ss -tlnp | grep -E '8000|8080|uvicorn|python' | head -20
# upload already done via sftp; restart chrome after browser-launch patch
chmod +x /opt/douyinWEB/backend/neko/browser-launch.sh
# convert CRLF if any
sed -i 's/\r$//' /opt/douyinWEB/backend/neko/browser-launch.sh
for id in 1 2; do
docker exec douyinweb-neko-$id supervisorctl restart google-chrome || true
done
sleep 6
# find API port from unit
PORT=$(systemctl show douyinweb-api -p Environment --value | tr ' ' '\n' | sed -n 's/^DY_API_PORT=//p' | head -1)
PORT=${PORT:-8000}
# also try from ExecStart
echo "PORT=$PORT"
# health via common ports
for p in $PORT 8000 8001 8088; do
code=$(curl -sS -o /tmp/h.json -w '%{http_code}' --max-time 2 http://127.0.0.1:$p/api/health || true)
echo "health :$p -> $code"
if [ "$code" = "200" ]; then
curl -fsS -X POST http://127.0.0.1:$p/api/youtube/studio/ingest -H 'Content-Type: application/json' -d '{"live_status":"probe","source":"smoke"}'
echo
curl -fsS -X POST http://127.0.0.1:$p/hub/youtube/live/ingest -H 'Content-Type: application/json' -d '{"live_status":"probe2","source":"smoke"}'
echo
# public studio urls via API process settings
curl -fsS "http://127.0.0.1:$p/api/youtube/neko/status" | python3 -c 'import sys,json; d=json.load(sys.stdin); print("assets", d.get("assets"));
[print(i.get("id"), i.get("studio_url"), i.get("ready")) for i in d.get("instances") or []]' || echo 'neko status needs auth'
break
fi
done
# frontend build for panel hint (quick)
if [ -d /opt/douyinWEB/frontend ]; then
cd /opt/douyinWEB/frontend
if command -v pnpm >/dev/null; then
pnpm exec next build 2>&1 | tail -30 || npm run build 2>&1 | tail -30 || true
elif [ -f package.json ]; then
npm run build 2>&1 | tail -40 || true
fi
fi
"""
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
s = c.open_sftp()
s.put(str(ROOT / "backend/neko/browser-launch.sh"), "/opt/douyinWEB/backend/neko/browser-launch.sh")
s.put(str(ROOT / "backend/neko/live-ops-extension/auto-dismiss.js"), "/opt/douyinWEB/backend/neko/live-ops-extension/auto-dismiss.js")
s.put(str(ROOT / "backend/neko/live-ops-extension/manifest.json"), "/opt/douyinWEB/backend/neko/live-ops-extension/manifest.json")
with s.file("/tmp/neko_continue2.sh", "w") as f:
f.write(REMOTE)
s.close()
_i, o, e = c.exec_command("bash /tmp/neko_continue2.sh", timeout=600)
o.channel.settimeout(600)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR", err[:2500])
c.close()