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>
95 lines
3.3 KiB
Python
95 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Fix time-slot mode: auto-enable relay + kick active channel."""
|
|
from __future__ import annotations
|
|
|
|
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_relay_pipeline.py",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
]
|
|
|
|
|
|
def main() -> int:
|
|
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 douyinweb-web
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python <<'PY'
|
|
import asyncio
|
|
from app.db import init_db, get_settings_map
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline as pipe
|
|
from app import youtube_neko, yt_assign_db, youtube_relay_db
|
|
|
|
init_db()
|
|
|
|
async def run():
|
|
# Re-arm time slot mode (starts worker + kicks active channel)
|
|
st = await pipe.set_time_slot_mode(True)
|
|
cfg = get_settings_map()
|
|
print("settings_relay", cfg.get("youtube_relay_enabled"), "slot", cfg.get("youtube_relay_time_slot_mode"))
|
|
print("pipeline_running", bool(pipe._task and not pipe._task.done()))
|
|
print("status_enabled", st.get("enabled"), "pushing", st.get("pushing_count"))
|
|
print("winner", st.get("exclusive_winner_group_id"))
|
|
groups = yt_assign_db.list_groups(include_urls=False)
|
|
for g in groups:
|
|
if not (g.get("has_stream_key") or str(g.get("stream_key") or "").strip()):
|
|
continue
|
|
gid = str(g.get("id") or "")
|
|
rs = youtube_relay_db.get_relay_state(gid) or {}
|
|
print("keyed", g.get("name"), "neko", g.get("neko_instance_id"), "relay", rs.get("status"), str(rs.get("error") or "")[:100])
|
|
nid = int(g.get("neko_instance_id") or 0)
|
|
if nid:
|
|
s = youtube_neko._container_state(nid)
|
|
print(" neko_state", s.get("running"), s.get("ready"), s.get("status"))
|
|
# give kick a moment
|
|
await asyncio.sleep(2)
|
|
st2 = pipe.status()
|
|
print("after_kick pushing", st2.get("pushing_count"), "winner", st2.get("exclusive_winner_group_id"))
|
|
for row in st2.get("groups") or []:
|
|
if row.get("has_stream_key") or row.get("manual_hold") or row.get("is_pushing") or row.get("business_status") in {"waiting_source","streaming","relay_starting","monitoring"}:
|
|
print("row", row.get("name"), row.get("business_status"), row.get("business_note"), "neko_run", (row.get("neko") or {}).get("running"))
|
|
|
|
asyncio.get_event_loop().run_until_complete(run())
|
|
PY
|
|
"""
|
|
print("remote…")
|
|
_, stdout, stderr = c.exec_command(cmd, timeout=360)
|
|
out = stdout.read().decode("utf-8", "replace")
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
print(out[-5000:] if len(out) > 5000 else out)
|
|
if err.strip():
|
|
print("STDERR", err[-2000:])
|
|
code = stdout.channel.recv_exit_status()
|
|
print("exit", code)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|