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

91 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy relay+Neko combined status poll optimization."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "108.174.50.68"
ROOT = Path(__file__).resolve().parents[1]
APP = "/opt/douyinWEB"
FILES = [
"backend/app/youtube_relay_pipeline.py",
"backend/app/youtube_neko.py",
"frontend/src/lib/ytRelayStatus.ts",
"frontend/src/components/YtRelayProStatusPanel.tsx",
]
REMOTE = r"""#!/usr/bin/env bash
set -euo pipefail
systemctl restart douyinweb-api
sleep 4
systemctl is-active douyinweb-api
cd /opt/douyinWEB/backend
.venv/bin/python - <<'PY'
from app.youtube_relay_pipeline import youtube_relay_pipeline
st = youtube_relay_pipeline.status()
print("groups", st.get("group_count"), "pushing", st.get("pushing_count"))
for g in st.get("groups") or []:
neko = g.get("neko") or {}
print(
"g", g.get("name"),
"biz", g.get("business_status"),
"note", (g.get("business_note") or "")[:40],
"neko_id", g.get("neko_instance_id"),
"neko_run", neko.get("running"),
"neko_ready", neko.get("ready"),
"url", neko.get("studio_url"),
)
assert any(g.get("neko") is not None or int(g.get("neko_instance_id") or 0) == 0 for g in (st.get("groups") or []))
print("neko_embedded_ok")
PY
cd /opt/douyinWEB/frontend && npm run build
systemctl restart douyinweb-web
sleep 3
systemctl is-active douyinweb-web
echo DONE
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
print("upload", rel)
sftp.put(str(ROOT / rel), f"{APP}/{rel}")
with sftp.file("/tmp/deploy_opt3.sh", "w") as f:
f.write(REMOTE)
sftp.chmod("/tmp/deploy_opt3.sh", 0o755)
sftp.close()
chan = c.get_transport().open_session()
chan.settimeout(900)
chan.get_pty(width=160, height=40)
chan.exec_command("bash /tmp/deploy_opt3.sh")
while True:
if chan.recv_ready():
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
if chan.recv_stderr_ready():
print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True)
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
break
time.sleep(0.25)
while chan.recv_ready():
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
code = chan.recv_exit_status()
c.close()
print("\nexit", code)
return code
if __name__ == "__main__":
raise SystemExit(main())