douyinWEB/scripts/_deploy_douyin_live_web.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

56 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy Douyin live-map web changes when git remote is unavailable."""
import time
import paramiko
HOST = "107.173.30.245"
REPO = "/opt/douyinWEB"
LOCAL = r"C:/Users/admin/Desktop/douyinWEB"
FILES = [
"backend/app/douyin_live.py",
"backend/app/db.py",
"backend/app/main.py",
"frontend/src/lib/douyinLive.ts",
"frontend/src/components/DouyinLiveBadge.tsx",
"frontend/src/components/Shell.tsx",
"frontend/src/components/YtAssignPanel.tsx",
"frontend/src/app/page.tsx",
"frontend/src/app/rooms/page.tsx",
"frontend/src/app/shorts/page.tsx",
"frontend/src/app/slots/page.tsx",
"frontend/src/app/anchors/page.tsx",
]
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]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_dylive_{ts} && ls -lh /tmp/monitor.db.bak_dylive_{ts}"))
sftp = c.open_sftp()
for rel in FILES:
remote = f"{REPO}/{rel.replace(chr(92), '/')}"
local = f"{LOCAL}/{rel.replace(chr(92), '/')}"
print("[upload]", rel)
sftp.put(local, remote)
sftp.close()
print("[verify api route]", run(f"grep -n douyin/live-map {REPO}/backend/app/main.py | head -3"))
print("[api restart]", run("systemctl restart douyinweb-api; sleep 5; systemctl is-active douyinweb-api"))
print("[npm build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -25", timeout=360))
print("[web restart]", run("systemctl restart douyinweb-web; sleep 4; systemctl is-active douyinweb-web"))
print("[health api]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/douyin/live-map"))
print("[health web]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4015/youtube"))
c.close()
print("DONE")