72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy relay timestamp fix to 10.88.0.5 and restart line 1."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.5", "eric", "4669805"
|
|
REMOTE_BASE = "/opt/live/d2ypp"
|
|
LANE1 = "youtube2__ch_mp9mm36r_2wn0r"
|
|
LOCAL = Path(__file__).resolve().parent.parent / "douyin_youtube_ffplay.py"
|
|
|
|
|
|
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> 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)
|
|
|
|
tmp = f"/tmp/douyin_youtube_ffplay.py.{int(time.time())}"
|
|
sftp = c.open_sftp()
|
|
sftp.put(str(LOCAL), tmp)
|
|
sftp.close()
|
|
print(
|
|
run(
|
|
c,
|
|
f"echo {PASS!r} | sudo -S -p '' cp {tmp} {REMOTE_BASE}/douyin_youtube_ffplay.py && "
|
|
f"sudo chown root:root {REMOTE_BASE}/douyin_youtube_ffplay.py && echo uploaded",
|
|
)
|
|
)
|
|
|
|
print("restart:", run(
|
|
c,
|
|
"curl -sS -m 60 -X POST 'http://127.0.0.1:8001/restart' "
|
|
"-H 'Content-Type: application/json' "
|
|
f"-d '{{\"process\":\"{LANE1}\"}}'",
|
|
)[:400])
|
|
|
|
print("waiting 45s...")
|
|
time.sleep(45)
|
|
|
|
log = f"{REMOTE_BASE}/.pm2/logs/{LANE1}-out.log"
|
|
print("\n=== profile ===")
|
|
print(run(c, f"grep -E 'wallclock live pacing|speed=|invalid dropping' {log} | tail -15"))
|
|
print("\n=== ffmpeg cmd ===")
|
|
print(run(c, "ps auxww | grep 'hey4-d3mu' | grep -v grep | head -1")[:500])
|
|
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") == LANE1:
|
|
print(
|
|
f"\nmonitor: status={entry.get('business_status')} "
|
|
f"speed={entry.get('ffmpeg_speed')} "
|
|
f"process={entry.get('process_status')}"
|
|
)
|
|
except json.JSONDecodeError:
|
|
print(raw[:800])
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|