#!/usr/bin/env python3 """Emergency: free RAM on dylive, revive API/web. Never recreate Neko; docker stop OK.""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(10): try: c.connect( "107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=90, ) break except Exception as e: print("retry", i, e, flush=True) time.sleep(2) else: raise SystemExit("ssh fail") def run(cmd: str, t: int = 90) -> str: print(f"\n$ {cmd[:100]}", flush=True) _i, o, e = c.exec_command(cmd, timeout=t) o.channel.settimeout(t) try: out = (o.read() + e.read()).decode("utf-8", "replace") except Exception as ex: out = f"TIMEOUT/ERR {ex}\n" print(out[-6000:] if len(out) > 6000 else out, flush=True) return out run("free -m | head -2; uptime") run("ps aux --sort=-%mem | head -15") # stop ALL douyinweb-neko to free RAM (start later if needed) — no recreate run( "docker ps -q --filter name=douyinweb-neko | xargs -r docker stop; " "docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort", t=120, ) # stop leftover non-app if any (ntfy etc) — user previously OK stopping WP/umami/nsq run( "docker ps --format '{{.Names}}' | grep -E '^(ntfy-|umami-|nomadro-|deploy-nsq)' | xargs -r docker stop; " "free -m | head -2", t=90, ) run("sync; echo 1 > /proc/sys/vm/drop_caches 2>/dev/null; free -m | head -2") # revive API — may be crashed but unit active zombie run( "systemctl reset-failed douyinweb-api douyinweb-web 2>/dev/null; " "systemctl restart douyinweb-api; sleep 4; " "systemctl restart douyinweb-web; sleep 3; " "systemctl is-active douyinweb-api douyinweb-web caddy; " "ss -lntp | grep -E ':4015|:8014|:443' | head -10", t=120, ) run( "curl -sS -m 8 -o /dev/null -w 'w:%{http_code}\\n' http://127.0.0.1:4015/youtube; " "curl -sS -m 8 -o /dev/null -w 'a:%{http_code}\\n' http://127.0.0.1:8014/api/health; " "curl -sS -m 10 -o /dev/null -w 'pub:%{http_code}\\n' -H 'Host: dylive.nomadro.com' " "http://127.0.0.1/youtube || true; " "free -m | head -2; uptime", t=60, ) c.close() print("DONE")