#!/usr/bin/env python3 """Deploy relay fix, auto-tune hardware profile, and restart Pro lanes.""" from __future__ import annotations import json import time from pathlib import Path import paramiko HOST, USER, PASS = "10.88.0.4", "eric", "4669805" ROOT = Path(__file__).resolve().parent.parent REMOTE_BASE = "/home/eric/d2ypp2-src" LANES = ["youtube2__ch_mpwri36r_z5lm2", "youtube2__ch_mpyvqkc0_gj63k"] UPLOADS = { ROOT / "douyin_youtube_ffplay.py": f"{REMOTE_BASE}/douyin_youtube_ffplay.py", ROOT / "scripts" / "hardware_probe.py": f"{REMOTE_BASE}/scripts/hardware_probe.py", ROOT / "config" / "hardware.env.example": f"{REMOTE_BASE}/config/hardware.env.example", ROOT / "youtube.py": f"{REMOTE_BASE}/youtube.py", ROOT / "src" / "spider.py": f"{REMOTE_BASE}/src/spider.py", ROOT / "src" / "recorder_config.py": f"{REMOTE_BASE}/src/recorder_config.py", } def run(c: paramiko.SSHClient, cmd: str, timeout: int = 90) -> str: _, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True) return (o.read() + e.read()).decode("utf-8", "replace") def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, username=USER, password=PASS, timeout=20) sftp = c.open_sftp() for local, remote in UPLOADS.items(): sftp.put(str(local), remote) print(f"uploaded {remote}") sftp.close() print( run( c, f"echo '{PASS}' | sudo -S -p '' chown -R eric:eric {REMOTE_BASE}/config && " f"chmod -R u+rwX {REMOTE_BASE}/config && echo perms_ok", timeout=30, ) ) probe_raw = run( c, f"cd {REMOTE_BASE} && . .venv/bin/activate && " "python scripts/hardware_probe.py --write --apply-youtube-defaults", timeout=120, ) print(probe_raw[:3500]) print("\n=== hardware.env ===") print(run(c, f"grep LIVE_RELAY {REMOTE_BASE}/config/hardware.env 2>/dev/null || true")) print("\n=== lane ini ===") print( run( c, f"grep -H 'video_mode\\|fast_audio\\|bitrate' {REMOTE_BASE}/config/youtube.youtube2__ch_*.ini 2>/dev/null | head -10", )[:1500] ) for lane in LANES: print(run(c, f"curl -sS -m 60 'http://127.0.0.1:8001/restart?process={lane}'")[:220]) time.sleep(4) print("waiting 50s...") time.sleep(50) print(run(c, "pgrep -af 'ffmpeg.*rtmps' || echo none")[:4000]) for lane in LANES: print(f"\n=== {lane} log ===") print( run( c, f"grep -E 'hardware relay|stream copy|YouTube Live profile|speed=' " f"{REMOTE_BASE}/.pm2/logs/{lane}-out.log | tail -6", )[:1200] ) raw = run(c, "curl -sS -m 15 'http://127.0.0.1:8001/process_monitor?family=youtube&light=1'") try: data = json.loads(raw) for entry in data.get("entries", []): if entry.get("pm2") in LANES: print( f"{entry['pm2']}: {entry.get('business_status')} " f"speed={entry.get('ffmpeg_speed')} room={entry.get('source_room_id')}" ) except json.JSONDecodeError: print(raw[:1500]) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())