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

55 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
"""Safe deploy yt-long module (default OFF — no Shorts impact)."""
import sys, time, paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd, timeout=600):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace").strip()
DB = f"{REPO}/backend/data/monitor.db"
before = run(f"stat -c '%s' {DB}")
print("[db before]", before)
# stash only code files that block pull
print("[stash]", run(
f"cd {REPO} && git stash push -m auto-before-yt-long -- "
"extensions/dylive-helper/manifest.json "
"extensions/dylive-helper/package.json "
"extensions/dylive-helper/src/content.ts "
"frontend/public/manifest.webmanifest "
"frontend/public/sw.js "
"frontend/src/components/PwaInstallBanner.tsx "
"|| true"
))
print("[pull]", run(f"cd {REPO} && git pull --ff-only origin test1 && git log --oneline -1"))
print("[api restart]")
run("systemctl restart douyinweb-api")
for _ in range(30):
if run("systemctl is-active douyinweb-api", timeout=15) == "active":
print("[api] active")
break
time.sleep(2)
print("[verify]", run(r"""cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
from app import db
from app.yt_long_pipeline import yt_long_pipeline
db.init_db()
st = yt_long_pipeline.status()
print('enabled', st.get('enabled'))
print('daily_max', st.get('daily_max'))
assert st.get('enabled') is False, 'must stay disabled'
print('detect_ok')
PY"""))
print("[build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -n 25", timeout=600))
run("systemctl restart douyinweb-web")
time.sleep(2)
after = run(f"stat -c '%s' {DB}")
print("[db after]", after, "delta", int(after)-int(before) if before.isdigit() and after.isdigit() else "?")
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
print(run("curl -sS -m 15 http://127.0.0.1:8787/api/yt-long/status | head -c 400"))
c.close()
print("DONE")