This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build. Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy relay-slot fix to 192.168.2.237 and restart active youtube lane."""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import json
|
|
import paramiko
|
|
from pathlib import Path
|
|
|
|
HOST, USER, PW = "192.168.2.237", "eric", "4669805"
|
|
BASE = "/home/eric/d2ypp2-src"
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
FILES = [
|
|
"src/youtube_relay_slot.py",
|
|
"youtube.py",
|
|
"douyin_youtube_ffplay.py",
|
|
"src/hub_routes.py",
|
|
]
|
|
PROC = "youtube2__ch_mpwri36r_z5lm2"
|
|
|
|
|
|
def put_lf(sftp, local: Path, remote: str) -> None:
|
|
data = local.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
sftp.putfo(io.BytesIO(data), remote)
|
|
|
|
|
|
def run(ssh, cmd, timeout=120):
|
|
_, o, e = ssh.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace").strip()
|
|
|
|
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(HOST, username=USER, password=PW, timeout=25)
|
|
sftp = ssh.open_sftp()
|
|
install_cmds = []
|
|
for rel in FILES:
|
|
local = ROOT / rel
|
|
tmp = f"/tmp/_deploy_{rel.replace('/', '_')}"
|
|
dest = f"{BASE}/{rel.replace(chr(92), '/')}"
|
|
put_lf(sftp, local, tmp)
|
|
mode = "0644"
|
|
install_cmds.append(f"install -m {mode} {tmp} {dest}")
|
|
print("staged", rel)
|
|
sftp.close()
|
|
print(run(ssh, f"echo '{PW}' | sudo -S -p '' bash -lc \"{' && '.join(install_cmds)}\""))
|
|
|
|
print("\n=== restart lane ===")
|
|
print(
|
|
run(
|
|
ssh,
|
|
f"curl -sS -m 90 -X POST 'http://127.0.0.1:8001/restart' "
|
|
f"-H 'Content-Type: application/json' "
|
|
f"-d '{{\"process\":\"{PROC}\"}}'",
|
|
)
|
|
)
|
|
|
|
import time
|
|
|
|
time.sleep(8)
|
|
print("\n=== ffmpeg ===")
|
|
print(run(ssh, "pgrep -af 'ffmpeg.*rtmps' | grep -v pgrep | head -2 || echo none"))
|
|
print("\n=== log tail ===")
|
|
print(run(ssh, f"tail -20 {BASE}/.pm2/logs/{PROC}-out.log"))
|
|
print("\n=== dashboard ===")
|
|
dash = json.loads(run(ssh, "curl -sS -m 12 http://127.0.0.1:8001/hub/dashboard"))
|
|
for p in dash.get("live", {}).get("processes", []):
|
|
if PROC in p.get("pm2", ""):
|
|
print(
|
|
p.get("pm2"),
|
|
p.get("business_status"),
|
|
"pushing=",
|
|
p.get("is_pushing"),
|
|
"note=",
|
|
(p.get("business_note") or "")[:120],
|
|
)
|
|
ssh.close()
|