68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
|
|
BASE = "/home/eric/d2ypp2-src"
|
|
|
|
|
|
def run(cmd: str, timeout: int = 120) -> str:
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
client.connect(HOST, username=USER, password=PASS, timeout=20)
|
|
_, stdout, stderr = client.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout)
|
|
out = (stdout.read() + stderr.read()).decode("utf-8", "replace")
|
|
client.close()
|
|
return out.strip()
|
|
|
|
|
|
def main() -> int:
|
|
print("=== process runner state ===")
|
|
raw = run(f"cat {BASE}/.process_runner/state.json 2>/dev/null || echo '{{}}'")
|
|
try:
|
|
state = json.loads(raw)
|
|
for name, row in sorted(state.items()):
|
|
if "youtube" not in name:
|
|
continue
|
|
print(name, "pid=", row.get("pid"), "status=", row.get("status"), "script=", row.get("script"))
|
|
except json.JSONDecodeError:
|
|
print(raw[:2000])
|
|
|
|
print("\n=== running youtube/ffmpeg ===")
|
|
print(run("pgrep -af 'youtube.py|ffmpeg.*rtmps' | grep -v pgrep || echo none"))
|
|
|
|
print("\n=== try restart pro lanes via api ===")
|
|
for proc in ("youtube2__ch_mpwri36r_z5lm2", "youtube2__ch_mpyvqkc0_gj63k"):
|
|
out = run(
|
|
"curl -sS -m 60 -X POST 'http://127.0.0.1:8001/restart' "
|
|
"-H 'Content-Type: application/json' "
|
|
f"-d '{{\"process\":\"{proc}\"}}'"
|
|
)
|
|
print(proc, out[:800])
|
|
|
|
print("\n=== after start ===")
|
|
print(run("sleep 8; pgrep -af 'youtube.py' | grep -v pgrep"))
|
|
print(run("pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep"))
|
|
raw = run("curl -sS -m 12 'http://127.0.0.1:8001/process_monitor?family=youtube'")
|
|
try:
|
|
data = json.loads(raw)
|
|
for row in data.get("entries") or []:
|
|
print(
|
|
row.get("pm2"),
|
|
row.get("business_status"),
|
|
row.get("is_pushing"),
|
|
row.get("label"),
|
|
row.get("source_display"),
|
|
)
|
|
except json.JSONDecodeError:
|
|
print(raw[:2000])
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|