#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Finish VPS API restart + force-open Live tabs on ops-neko 1/2.""" import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def main() -> None: v = paramiko.SSHClient() v.set_missing_host_key_policy(paramiko.AutoAddPolicy()) v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False) print("VPS restart…", flush=True) # non-blocking-ish v.exec_command("systemctl restart douyinweb-api >/tmp/api_rst.log 2>&1 &", timeout=15) time.sleep(8) _i, o, e = v.exec_command( "systemctl is-active douyinweb-api; " "grep -c wait_group_ready_for_live /opt/douyinWEB/backend/app/youtube_relay_pipeline.py", timeout=30, ) print((o.read() + e.read()).decode(), flush=True) v.close() p = paramiko.SSHClient() p.set_missing_host_key_policy(paramiko.AutoAddPolicy()) p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False) sftp = p.open_sftp() with sftp.file("/tmp/_force_ops_live.py", "wb") as f: f.write( b""" import sys, json sys.path.insert(0, "/opt/douyinWEB/backend") from app import ops_neko, ops_neko_db print("role", ops_neko_db.peer_status()) print("instances", [{k: r.get(k) for k in ("slot","name","want_running","bind_remote_group_id")} for r in ops_neko_db.list_instances()]) cards = ops_neko.pull_remote_cards() print("cards_ok", cards.get("ok"), "n", len(cards.get("cards") or []), "err", cards.get("error")) for c in (cards.get("cards") or []): if c.get("ops_neko_slot") or c.get("neko_open_prefer")=="remote": print(" card", c.get("name"), "slot", c.get("ops_neko_slot"), "prefer", c.get("neko_open_prefer"), "yt", c.get("youtube_channel_id")) # force both slots for slot in (1, 2): yt = "" for c in (cards.get("cards") or []): if int(c.get("ops_neko_slot") or 0) == slot: yt = str(c.get("youtube_channel_id") or "") break print("ensure", slot, ops_neko.ensure_slot_live_studio(slot, youtube_channel_id=yt)) print("bound_pass", ops_neko.ensure_bound_slots_live_studio()) print("catalog", ops_neko.push_catalog_to_hub()) """ ) sftp.close() _i, o, e = p.exec_command( "echo 4669805 | sudo -S -p '' bash -lc '" "cd /opt/douyinWEB/backend; " "PY=python3; [ -x .venv/bin/python ] && PY=.venv/bin/python; " "$PY /tmp/_force_ops_live.py" "'", timeout=180, ) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) p.close() if __name__ == "__main__": main()