123 lines
4.0 KiB
Python
123 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy Preparing-stream gate + orphan-ffmpeg status flap fix to dylive."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def ssh():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, t=300):
|
|
print(f"\n$ {cmd[:240]}", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
code = o.channel.recv_exit_status()
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-18000:] if len(out) > 18000 else out, flush=True)
|
|
return code, out
|
|
|
|
|
|
c = ssh()
|
|
sftp = c.open_sftp()
|
|
for rel, remote in [
|
|
("backend/neko/cdp_studio_scrape.py", "/tmp/cdp_studio_scrape.py"),
|
|
("backend/app/youtube_neko.py", "/tmp/youtube_neko.py"),
|
|
("backend/app/youtube_relay_pipeline.py", "/tmp/youtube_relay_pipeline.py"),
|
|
("backend/tests/test_preparing_stream_gate.py", "/tmp/test_preparing_stream_gate.py"),
|
|
]:
|
|
sftp.put(str(ROOT / rel), remote)
|
|
sftp.close()
|
|
|
|
code, _ = run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
install -m 0644 /tmp/cdp_studio_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
|
|
install -m 0644 /tmp/youtube_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
install -m 0644 /tmp/youtube_relay_pipeline.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
install -m 0644 /tmp/test_preparing_stream_gate.py /opt/douyinWEB/backend/tests/test_preparing_stream_gate.py
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python -m py_compile app/youtube_neko.py app/youtube_relay_pipeline.py neko/cdp_studio_scrape.py
|
|
./.venv/bin/python -m pytest -q tests/test_preparing_stream_gate.py
|
|
systemctl restart douyinweb-api.service
|
|
sleep 4
|
|
systemctl is-active douyinweb-api.service
|
|
""",
|
|
)
|
|
assert code == 0, "deploy failed"
|
|
|
|
# Probe asian streetfood / status flap + studio scrape fields
|
|
code2, out2 = run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
import json, urllib.request
|
|
from app import db, yt_assign_db, youtube_relay_db
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline as pipe, _ffmpeg_pid_alive
|
|
from app import youtube_neko
|
|
|
|
# Find asian streetfood cards
|
|
groups = yt_assign_db.list_groups(featured_only=False)
|
|
hits = [g for g in groups if "asian" in str(g.get("name") or "").lower()]
|
|
print("asian_groups", [(g.get("id"), g.get("name"), g.get("neko_instance_id"), g.get("category")) for g in hits])
|
|
st = pipe.status()
|
|
rows = {str(r.get("group_id") or ""): r for r in (st.get("groups") or [])}
|
|
for g in hits:
|
|
gid = str(g.get("id") or "")
|
|
mon = rows.get(gid) or {}
|
|
dbst = youtube_relay_db.get_relay_state(gid) or {}
|
|
pid = int(dbst.get("ffmpeg_pid") or 0)
|
|
print(json.dumps({
|
|
"gid": gid[:8],
|
|
"name": g.get("name"),
|
|
"biz": mon.get("business_status"),
|
|
"row_status": mon.get("status"),
|
|
"is_pushing": mon.get("is_pushing"),
|
|
"db_status": dbst.get("status"),
|
|
"ffmpeg_pid": pid,
|
|
"pid_alive": _ffmpeg_pid_alive(pid),
|
|
"session": gid in getattr(pipe, "_sessions", {}),
|
|
}, ensure_ascii=False))
|
|
|
|
# Live CDP scrape on neko-7 if present
|
|
nid = 7
|
|
try:
|
|
sig = youtube_neko._cdp_studio_page_signals(nid, force=True, max_age_sec=0.0)
|
|
print("cdp7", json.dumps({k: sig.get(k) for k in (
|
|
"ok","live_status","on_air","preparing_stream","control_ready","health","encoder_receiving"
|
|
)}, ensure_ascii=False))
|
|
except Exception as e:
|
|
print("cdp7_err", e)
|
|
|
|
cfg = db.get_settings_map()
|
|
print("relay", cfg.get("youtube_relay_enabled"), "timeslot_test", cfg.get("youtube_relay_timeslot_test"),
|
|
"winner", str(cfg.get("youtube_relay_timeslot_test_group_id") or "")[:8])
|
|
PY
|
|
""",
|
|
)
|
|
print("probe_exit", code2)
|
|
c.close()
|
|
print("DONE", time.strftime("%H:%M:%S"))
|