#!/usr/bin/env python3 """Emergency: stop all Neko on VPS to free RAM, then bring dylive + frpp + wg back.""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") def ssh(tries=10): last = None for i in range(tries): try: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 22, "root", "Xiao4669805", timeout=40, banner_timeout=120, allow_agent=False, look_for_keys=False, ) print(f"ssh ok {i}", flush=True) return c except Exception as ex: last = ex print(f"retry {i} {ex}", flush=True) time.sleep(3) raise SystemExit(str(last)) def run(c, cmd, t=90): print(f"\n$ {cmd[:200]}", flush=True) _i, o, e = c.exec_command(cmd, timeout=t) code = o.channel.recv_exit_status() out = (o.read() + e.read()).decode("utf-8", "replace") print((out[-5000:] if len(out) > 5000 else out) or f"(empty {code})", flush=True) return code c = ssh() # Stop every neko container NOW (biggest RAM eaters) run( c, "uptime; free -h | head -2; " "timeout 40 docker ps -aq --filter name=douyinweb-neko | xargs -r docker stop -t 2; " "timeout 40 docker ps -aq --filter name=neko | xargs -r docker stop -t 2; " "echo NEKO_STOPPED; free -h | head -2; uptime", 120, ) # Drop other heavy leftovers if any chrome outside docker run( c, "pkill -9 -f 'google-chrome|chromium|chromedriver' 2>/dev/null || true; " "sleep 2; free -h | head -2; uptime", 30, ) # Bring core services run( c, "systemctl restart frpp; " "systemctl restart douyinweb-pb; " "systemctl restart douyinweb-yt; " "systemctl restart douyinweb-api; " "systemctl restart douyinweb-web; " "systemctl restart caddy; " "sleep 5; " "systemctl is-active frpp caddy douyinweb-api douyinweb-web douyinweb-yt douyinweb-pb; " "ss -lntp | grep -E ':8014|:4015|:443|:4014|:8092|:8020' || true; " "curl -sS -m 10 http://127.0.0.1:8014/api/health | head -c 220; echo; " "curl -sS -m 8 -o /dev/null -w 'web=%{http_code}\\n' http://127.0.0.1:4015/", 120, ) # WG run( c, "wg-quick down wg-dy 2>/dev/null; wg-quick up wg-dy; sleep 2; " "wg show wg-dy | head -15; " "ss -lntp | grep -E '4014|7000|7500|frp' || true; " "systemctl is-active frpp", 45, ) c.close() print("DONE_EMERGENCY", flush=True)