# -*- coding: utf-8 -*- from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") CMD = r""" cd /opt/douyinWEB/backend .venv/bin/python <<'PY' import os, signal, time, subprocess from app import db, youtube_relay_db, yt_assign_db from app.youtube_relay_pipeline import _group_in_active_slot winner=None for g in yt_assign_db.list_groups(include_urls=False, include_secret=False): if g.get('has_stream_key') and g.get('enabled') and _group_in_active_slot(str(g.get('id')), keyed_only=True): winner=g; break st=youtube_relay_db.get_relay_state(str(winner['id'])) or {} if winner else {} keep=int(st.get('ffmpeg_pid') or 0) def yt_ffmpegs(): out=[] for line in subprocess.getoutput('ps -eo pid,cmd').splitlines(): if 'ffmpeg' not in line or 'rtmps.youtube' not in line: continue parts=line.strip().split(None,1) try: pid=int(parts[0]) except Exception: continue out.append((pid, parts[1][:100] if len(parts)>1 else '')) return out print('before', yt_ffmpegs()) for pid,_ in yt_ffmpegs(): if keep and pid==keep: print('KEEP', pid) continue try: os.kill(pid, signal.SIGTERM) print('KILLED', pid) except Exception as e: print('fail', pid, e) time.sleep(8) print('after', yt_ffmpegs()) st2=youtube_relay_db.get_relay_state(str(winner['id'])) or {} print('state', st2.get('status'), st2.get('ffmpeg_pid'), (st2.get('source_url') or '')[:50]) # if keep died, report alive={p for p,_ in yt_ffmpegs()} print('keep_alive', keep in alive) print('cookie', len(str(db.get_settings_map().get('dy_cookie') or ''))) PY """ c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=60, allow_agent=False, look_for_keys=False) _, o, e = c.exec_command(CMD, timeout=60) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err.strip(): print("STDERR", err[-1000:]) c.close()