sh2/d2ypp2/tools/verify_deploy_host04.py
2026-06-14 10:41:48 -05:00

80 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Post-deploy verify on 10.88.0.4."""
from __future__ import annotations
import json
import sys
import paramiko
HOST, USER, PASS, BASE = "10.88.0.4", "eric", "4669805", "/home/eric/d2ypp2-src"
OUT_PATH = sys.argv[1] if len(sys.argv) > 1 else None
def emit(text: str) -> None:
if OUT_PATH:
with open(OUT_PATH, "a", encoding="utf-8") as fh:
fh.write(text + "\n")
else:
sys.stdout.buffer.write((text + "\n").encode("utf-8", errors="replace"))
def run(ssh: paramiko.SSHClient, cmd: str, timeout: int = 90) -> 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 main() -> int:
if OUT_PATH:
open(OUT_PATH, "w", encoding="utf-8").close()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(HOST, username=USER, password=PASS, timeout=20)
checks = {
"health": run(ssh, "curl -sf -m 8 http://127.0.0.1:8001/health || echo DOWN"),
"hide_relay_snapshot": run(
ssh, f"grep -c 'HIDE_YOUTUBE_RELAY_SNAPSHOT = true' {BASE}/web-console/components/live-product/LiveYoutubeUnmannedView.tsx"
).strip(),
"hide_event_hub": run(
ssh, f"grep -c 'HIDE_YOUTUBE_LIVE_EVENT_HUB = true' {BASE}/web-console/components/live-product/LiveYoutubeUnmannedView.tsx"
).strip(),
"static_chunk": run(
ssh, f"ls {BASE}/web-console/out/_next/static/chunks/904-*.js 2>/dev/null | tail -1"
).strip(),
"proxychains_fn": run(
ssh, f"grep -c 'def _proxychains_config_for_push' {BASE}/douyin_youtube_ffplay.py"
).strip(),
"ffmpeg": run(ssh, "pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -2"),
}
emit("=== deploy verify ===")
for key, value in checks.items():
emit(f"{key}: {value[:500]}")
raw = run(ssh, "curl -sS -m 12 'http://127.0.0.1:8001/process_monitor?family=youtube'")
emit("\n=== lanes ===")
try:
for row in json.loads(raw).get("entries", []):
pm2 = row.get("pm2", "")
if pm2.startswith("youtube"):
emit(
f"{pm2}: {row.get('business_status')} pushing={row.get('is_pushing')} speed={row.get('ffmpeg_speed')}"
)
except json.JSONDecodeError:
emit(f"process_monitor failed: {raw[:300]}")
ok = (
"ok" in checks["health"]
and checks["hide_relay_snapshot"] == "1"
and checks["hide_event_hub"] == "1"
and checks["proxychains_fn"] == "1"
)
emit(f"\nDEPLOY_TEST: {'PASS' if ok else 'PARTIAL'}")
ssh.close()
return 0 if ok else 1
if __name__ == "__main__":
raise SystemExit(main())