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>
73 lines
3.0 KiB
Python
73 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy YouTube unmanned live relay (Douyin → RTMPS) — full backend + frontend."""
|
|
import os
|
|
import sys
|
|
import time
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "107.173.30.245"
|
|
REPO = "/opt/douyinWEB"
|
|
LOCAL = r"C:/Users/admin/Desktop/douyinWEB"
|
|
|
|
FILES = [
|
|
"backend/app/db.py",
|
|
"backend/app/main.py",
|
|
"backend/app/youtube_relay.py",
|
|
"backend/app/youtube_relay_db.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/youtube_relay_sessions.py",
|
|
"backend/app/youtube_relay_status.py",
|
|
"frontend/src/app/youtube/page.tsx",
|
|
"frontend/src/app/youtube-relay-log/page.tsx",
|
|
"frontend/src/components/Shell.tsx",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"frontend/src/components/YtRelayLiveLogCard.tsx",
|
|
"frontend/src/lib/ffmpegMetrics.ts",
|
|
"frontend/src/lib/ytRelayStatus.ts",
|
|
"frontend/src/lib/ytRelayUi.ts",
|
|
]
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(cmd: str, timeout: int = 360) -> str:
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
out = o.read().decode("utf-8", "replace").strip()
|
|
err = e.read().decode("utf-8", "replace").strip()
|
|
return (out + ("\n" + err if err else "")).strip()
|
|
|
|
|
|
ts = int(time.time())
|
|
print("[backup db]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_yt_relay_{ts} && ls -lh /tmp/monitor.db.bak_yt_relay_{ts}"))
|
|
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
remote = f"{REPO}/{rel.replace(chr(92), '/')}"
|
|
local = f"{LOCAL}/{rel.replace(chr(92), '/')}"
|
|
remote_dir = os.path.dirname(remote)
|
|
try:
|
|
sftp.stat(remote_dir)
|
|
except OSError:
|
|
run(f"mkdir -p {remote_dir}")
|
|
print("[upload]", rel)
|
|
sftp.put(local, remote)
|
|
sftp.close()
|
|
|
|
print("[verify relay route]", run(f"grep -n 'youtube/relay/status' {REPO}/backend/app/main.py | head -2"))
|
|
print("[verify relay module]", run(f"python3 -m py_compile {REPO}/backend/app/youtube_relay.py {REPO}/backend/app/youtube_relay_pipeline.py && echo py_ok"))
|
|
print("[api restart]", run("systemctl restart douyinweb-api; sleep 6; systemctl is-active douyinweb-api"))
|
|
print("[api health]", run("curl -s http://127.0.0.1:8014/api/health | head -c 400"))
|
|
print("[relay status]", run("curl -s http://127.0.0.1:8014/api/youtube/relay/status | head -c 500"))
|
|
print("[relay sessions]", run("curl -s 'http://127.0.0.1:8014/api/youtube/relay/sessions?limit=1' | head -c 300"))
|
|
print("[npm build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -30", timeout=600))
|
|
print("[web restart]", run("systemctl restart douyinweb-web; sleep 4; systemctl is-active douyinweb-web"))
|
|
print("[web youtube]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4015/youtube"))
|
|
print("[web relay-log]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4015/youtube-relay-log"))
|
|
c.close()
|
|
print("DONE")
|