sh2/d2ypp2/tools/check_relay_slot_hosts.py
eric 278b48497e Add YouTube relay log tooling and optional hub service controls.
This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 05:10:09 -05:00

149 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Check relay-slot bug presence on host03 and host05."""
from __future__ import annotations
import json
import paramiko
import sys
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOSTS = [
("10.88.0.3", "eric", "Xiao4669805", "/opt/live/d2ypp"),
("10.88.0.5", "eric", "4669805", "/home/eric/d2ypp2-src"),
]
def run(ssh, cmd, timeout=90):
_, o, e = ssh.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace").strip()
def check_host(host, user, pw, base):
print(f"\n{'='*72}\n{host} base={base}\n{'='*72}")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(host, username=user, password=pw, timeout=25)
except Exception as exc:
print(f"SSH FAIL: {exc}")
return
print("health:", run(ssh, "curl -sf -m 5 http://127.0.0.1:8001/health || echo FAIL"))
# --- code markers ---
markers = {
"old_len_recording_guard": run(
ssh, f"grep -n 'len(recording) > 0' {base}/youtube.py 2>/dev/null | head -3 || echo absent"
),
"new_relay_slot_import": run(
ssh,
f"grep -n 'youtube_relay_slot' {base}/youtube.py 2>/dev/null | head -3 || echo absent",
),
"relay_slot_module": run(
ssh, f"test -f {base}/src/youtube_relay_slot.py && echo present || echo missing"
),
"wrong_fallback_urls": run(
ssh,
f"grep -n 'url_line_list' {base}/youtube.py 2>/dev/null | grep fallback || echo absent",
),
"stream_input_filter": run(
ssh,
f"grep -n '_is_probable_stream_input' {base}/douyin_youtube_ffplay.py 2>/dev/null | head -1 || echo absent",
),
"hub_is_file_fix": run(
ssh,
f"grep -n 'url_file = Path' {base}/src/hub_routes.py 2>/dev/null | head -1 || echo absent",
),
}
print("\n--- code markers ---")
for k, v in markers.items():
print(f"{k}: {v}")
has_old_bug = "len(recording) > 0" in markers["old_len_recording_guard"]
has_fix = (
markers["relay_slot_module"] == "present"
and "absent" not in markers["new_relay_slot_import"]
and "absent" not in markers["stream_input_filter"]
)
print(f"\nBUG STATUS: old_guard={has_old_bug} fix_deployed={has_fix}")
# --- youtube processes ---
print("\n--- youtube processes ---")
print(run(ssh, "ps aux | grep -E 'python.*youtube\\.py' | grep -v grep | head -5 || echo none"))
# --- pm2 / local registry ---
print("\n--- process list (api) ---")
try:
dash = json.loads(run(ssh, "curl -sS -m 15 http://127.0.0.1:8001/hub/dashboard"))
yt_procs = [
p
for p in dash.get("live", {}).get("processes", [])
if "youtube" in str(p.get("pm2", "")).lower()
]
for p in yt_procs[:6]:
print(
f" {p.get('pm2')}: status={p.get('process_status')} "
f"biz={p.get('business_status')} pushing={p.get('is_pushing')} "
f"note={(p.get('business_note') or '')[:80]}"
)
if len(yt_procs) > 6:
print(f" ... +{len(yt_procs)-6} more")
except Exception as exc:
print(f"dashboard parse fail: {exc}")
# --- ffmpeg ---
print("\n--- ffmpeg rtmps ---")
print(run(ssh, "pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -3 || echo none"))
# --- find active youtube log ---
log_dir = f"{base}/.pm2/logs"
logs = run(ssh, f"ls -t {log_dir}/youtube2__*-out.log 2>/dev/null | head -5")
active_log = ""
for lg in logs.splitlines():
if not lg.strip():
continue
tail = run(ssh, f"tail -3 {lg}")
if "正在录制" in tail or "启动 YouTube" in tail or "正在直播中" in tail:
active_log = lg.strip()
break
if not active_log and logs.splitlines():
active_log = logs.splitlines()[0].strip()
if active_log:
print(f"\n--- log tail: {active_log.split('/')[-1]} ---")
print(run(ssh, f"tail -25 {active_log}")[-2500:])
print("\n--- log patterns (stuck live + blocked) ---")
patterns = run(
ssh,
f"grep -E '正在直播中|正在录制|启动 YouTube|推流已彻底停止|切换备用源|跳过非直链|len\\(recording\\)' "
f"{active_log} 2>/dev/null | tail -15",
)
print(patterns[-2000:] if patterns else "(no matches)")
# check wrong fallback in recent log
wrong_fb = run(
ssh,
f"grep -E '切换备用源 URL.*live\\.douyin\\.com' {active_log} 2>/dev/null | tail -5",
)
if wrong_fb:
print("\n--- WRONG FALLBACK (page URL as ffmpeg input) ---")
print(wrong_fb)
# --- is_file dashboard error ---
err_is_file = run(
ssh,
"curl -sS -m 12 http://127.0.0.1:8001/hub/dashboard | "
"python3 -c \"import sys,json; d=json.load(sys.stdin); "
"print([p.get('business_note') for p in d.get('live',{}).get('processes',[]) "
"if 'is_file' in str(p.get('business_note',''))][:3])\" 2>/dev/null || echo check_failed",
)
print(f"\n--- dashboard is_file errors: {err_is_file} ---")
ssh.close()
for h, u, p, b in HOSTS:
check_host(h, u, p, b)