douyinWEB/scripts/_deep_why_push_idle.py
2026-09-13 22:10:49 -05:00

55 lines
1.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Deep dive why push dies / idle after start."""
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(
r"""
# journal for relay/ffmpeg errors
journalctl -u douyinweb-api --since '15 min ago' --no-pager 2>/dev/null | grep -iE 'relay|ffmpeg|invalid|neko wait|blocked|NODATA|on_air|3fb8|streetfood|Connection refused|RTMP|error' | tail -60
cd /opt/douyinWEB/backend
python3 - <<'PY'
import sqlite3, json, time
con=sqlite3.connect('data/monitor.db')
con.row_factory=sqlite3.Row
gid='3fb8cbf7-2180-45bc-99f0-836169f0bf97'
r=dict(con.execute('select * from yt_relay_states where group_id=?',(gid,)).fetchone() or {})
print('=== STATE ===')
for k in ('status','error','ffmpeg_pid','push_seconds','started_at','updated_at','anchor_name'):
print(k, r.get(k))
print('updated_age', round(time.time()-float(r.get('updated_at') or 0),1))
log=r.get('recent_log')
try:
lines=json.loads(log) if isinstance(log,str) and log.startswith('[') else (log or '').splitlines()
except Exception:
lines=[str(log)]
print('=== FULL LOG (%d) ===' % len(lines))
for ln in lines:
print(ln if isinstance(ln,str) else ln)
# any other groups pushing?
print('=== OTHER RELAY ===')
for row in con.execute("select group_id,status,ffmpeg_pid,substr(error,1,80) err from yt_relay_states where status not in ('idle','stopped','paused_exclusive') or ffmpeg_pid>0"):
print(dict(row))
PY
""",
timeout=45,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()