80 lines
3.1 KiB
Python
80 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Finish host04 deploy: restart lanes and verify regression."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS, BASE = "10.88.0.4", "eric", "4669805", "/home/eric/d2ypp2-src"
|
|
|
|
|
|
def run(ssh: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str:
|
|
_, o, e = ssh.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout, get_pty=True)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def lane_names(ssh: paramiko.SSHClient) -> list[str]:
|
|
raw = run(ssh, f"ls {BASE}/config/youtube.youtube2__*.ini 2>/dev/null")
|
|
out: list[str] = []
|
|
for line in raw.splitlines():
|
|
name = line.rsplit("/", 1)[-1]
|
|
if name.startswith("youtube.") and name.endswith(".ini"):
|
|
out.append(name[len("youtube.") : -len(".ini")])
|
|
return sorted(out)
|
|
|
|
|
|
def main() -> int:
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
|
|
print("health:", run(ssh, "curl -sf -m 8 http://127.0.0.1:8001/health && echo OK"))
|
|
for proc in lane_names(ssh):
|
|
out = run(
|
|
ssh,
|
|
"curl -sS -m 60 -X POST 'http://127.0.0.1:8001/restart' "
|
|
"-H 'Content-Type: application/json' "
|
|
f"-d '{json.dumps({'process': proc})}'",
|
|
)
|
|
print(f"restart {proc}: {out[:240]}")
|
|
time.sleep(30)
|
|
|
|
copy_fn = run(ssh, f"grep -c _resolve_stream_copy_plan {BASE}/douyin_youtube_ffplay.py 2>/dev/null || echo 0").strip()
|
|
relay = run(ssh, f"grep -c relay_strategy {BASE}/config/hardware-profile.json 2>/dev/null || echo 0").strip()
|
|
ffmpeg = run(ssh, "pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -2")
|
|
profile = run(
|
|
ssh,
|
|
"grep -hE 'YouTube Live profile|stream copy|libx264' "
|
|
f"{BASE}/.pm2/logs/youtube2__*-out.log 2>/dev/null | tail -8",
|
|
)
|
|
qg = run(
|
|
ssh,
|
|
"curl -sS -m 12 http://127.0.0.1:8001/hub/youtube/quality_guard | "
|
|
"python3 -c \"import sys,json; d=json.load(sys.stdin); print(d.get('ffmpeg_profile',{}).get('target','?'))\"",
|
|
)
|
|
raw = run(ssh, "curl -sS -m 12 'http://127.0.0.1:8001/process_monitor?family=youtube'")
|
|
print("\n--- ffmpeg processes ---\n", ffmpeg)
|
|
print("\n--- push profile log ---\n", profile)
|
|
print("\n--- quality guard target ---\n", qg)
|
|
try:
|
|
rows = json.loads(raw).get("entries") or []
|
|
print("\n--- process_monitor ---")
|
|
for row in rows:
|
|
print(
|
|
f" {row.get('pm2')}: {row.get('business_status')} pushing={row.get('is_pushing')} "
|
|
f"speed={row.get('ffmpeg_speed')} display={row.get('source_display') or '-'}"
|
|
)
|
|
except json.JSONDecodeError:
|
|
print("process_monitor raw:", raw[:800])
|
|
|
|
ok = copy_fn in {"0", ""} and relay in {"0", ""} and ("libx264" in ffmpeg or "H.264 libx264" in profile)
|
|
print(f"\n回归源码: {'PASS' if ok else 'PARTIAL'} (copy_fn={copy_fn}, relay={relay}, libx264={'yes' if 'libx264' in ffmpeg else 'no'})")
|
|
ssh.close()
|
|
return 0 if ok else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|