# -*- coding: utf-8 -*- import json import time import paramiko HOST = "107.173.30.245" USER = "root" PASSWORD = "Xiao4669805" def main() -> None: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False) def exec_quiet(cmd: str, timeout: int = 90) -> str: chan = c.get_transport().open_session() chan.settimeout(timeout) chan.get_pty() chan.exec_command(cmd) buff = [] while True: if chan.recv_ready(): buff.append(chan.recv(65535).decode("utf-8", errors="replace")) if chan.exit_status_ready() and not chan.recv_ready(): break time.sleep(0.2) # drain while chan.recv_ready(): buff.append(chan.recv(65535).decode("utf-8", errors="replace")) code = chan.recv_exit_status() out = "".join(buff) print(f"$ {cmd}\nexit={code}\n{out[-1500:]}", flush=True) return out # restart in background so SSH doesn't hang on Type=notify exec_quiet("systemctl restart douyinweb-api --no-block; sleep 3; systemctl is-active douyinweb-api; systemctl status douyinweb-api --no-pager -l | head -n 20") for i in range(25): out = exec_quiet( "curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/status || echo fail", timeout=30, ) code = "".join(ch for ch in out if ch.isdigit())[-3:] print("probe", i, code, flush=True) if code.startswith("2"): break time.sleep(1) out = exec_quiet("curl -s -X POST http://127.0.0.1:8014/api/sessions/reconcile-stale", timeout=60) if "{" in out: js = out[out.index("{") :] print("RECONCILE_JSON", js[:2500], flush=True) out = exec_quiet("curl -s http://127.0.0.1:8014/api/sessions/active", timeout=40) if "{" in out: js = out[out.index("{") :] data = json.loads(js) print("active_total", data.get("total"), flush=True) now = time.time() for s in data.get("sessions") or []: started = float(s.get("started_at") or 0) el = int(now - started) if started else 0 h, r = divmod(el, 3600) m, sec = divmod(r, 60) print( f"LIVE {s.get('anchor_name')} {h}:{m:02d}:{sec:02d} room={s.get('room_id')}", flush=True, ) c.close() if __name__ == "__main__": main()