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

98 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy exclusive-live refinements + frontend toggle; smoke-test on VPS."""
from __future__ import annotations
import json
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
HOST = "108.174.50.68"
PASS = "Xiao4669805"
REPO = "/opt/douyinWEB"
FILES = [
"backend/app/youtube_neko.py",
"backend/app/youtube_relay_pipeline.py",
"backend/app/main.py",
"backend/app/db.py",
"frontend/src/components/YtAssignPanel.tsx",
]
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
print("uploaded", rel)
sftp.close()
cmd = r"""
set -e
systemctl restart douyinweb-api
cd /opt/douyinWEB/frontend && npm run build
systemctl restart douyinweb-web
sleep 4
systemctl is-active douyinweb-api
systemctl is-active douyinweb-web
cd /opt/douyinWEB/backend
.venv/bin/python - <<'PY'
from app import youtube_neko, yt_assign_db, youtube_relay_pipeline, db
cfg = db.get_settings_map()
print("exclusive_setting", cfg.get("youtube_relay_exclusive_live"))
# smoke: stop_instances_except / ensure_instance_running exist
assert hasattr(youtube_neko, "ensure_instance_running")
assert hasattr(youtube_relay_pipeline.youtube_relay_pipeline, "set_exclusive_live")
groups = yt_assign_db.list_groups(include_urls=False)
enabled = [g for g in groups if g.get("neko_enabled")]
print("enabled_neko", [(g.get("name"), g.get("neko_instance_id")) for g in enabled])
# Simulate exclusive: keep first enabled, stop others
if enabled:
keep = int(enabled[0].get("neko_instance_id") or 0)
stopped = youtube_neko.stop_instances_except(keep)
print("smoke_stop_except", keep, "stopped", stopped)
started = youtube_neko.ensure_instance_running(keep)
print("smoke_ensure_winner", started)
# restore
r = youtube_neko.restore_enabled_instances()
print("smoke_restore", r.get("ok"), "started", r.get("started") or r.get("detail", "")[:80])
st = youtube_relay_pipeline.youtube_relay_pipeline.status()
print("status_exclusive", st.get("settings", {}).get("youtube_relay_exclusive_live"), st.get("exclusive_winner_group_id"))
PY
# in-process API smoke (avoids session auth on curl)
cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
import asyncio
from app.youtube_relay_pipeline import youtube_relay_pipeline
async def main():
st = await youtube_relay_pipeline.set_exclusive_live(True)
print("api_toggle", st.get("settings", {}).get("youtube_relay_exclusive_live"))
asyncio.run(main())
PY
"""
_i, o, e = c.exec_command(cmd, timeout=700)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR", err[-2500:])
c.close()
if __name__ == "__main__":
main()