126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Nuclear recovery: stop Docker entirely, free RAM, start caddy+api+web+frpp+wg."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh(port=22, user="root", pw="Xiao4669805", tries=12):
|
|
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",
|
|
port,
|
|
user,
|
|
pw,
|
|
timeout=40,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
print(f"ssh :{port} ok {i}", flush=True)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"ssh :{port} retry {i} {ex}", flush=True)
|
|
time.sleep(3)
|
|
raise SystemExit(f"ssh fail :{port} {last}")
|
|
|
|
|
|
def run(c, cmd, t=180):
|
|
print(f"\n$ {cmd[:230]}", 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[-7000:] if len(out) > 7000 else out) or f"(empty {code})", flush=True)
|
|
return code
|
|
|
|
|
|
v = ssh()
|
|
|
|
# Stop docker hard — Neko cannot run on 3.8G with load 200
|
|
run(
|
|
v,
|
|
"systemctl stop docker.socket docker containerd 2>/dev/null; "
|
|
"pkill -9 -f dockerd; pkill -9 -f containerd; pkill -9 chrome; pkill -9 chromium; "
|
|
"sleep 3; free -h | head -2; uptime; "
|
|
"ps aux | grep -E 'chrome|dockerd|neko' | grep -v grep | wc -l",
|
|
90,
|
|
)
|
|
|
|
# Ensure caddy timeout and start core stack WITHOUT docker
|
|
run(
|
|
v,
|
|
"mkdir -p /etc/systemd/system/caddy.service.d; "
|
|
"printf '[Service]\\nTimeoutStartSec=300\\nTimeoutStopSec=30\\n' > /etc/systemd/system/caddy.service.d/timeout.conf; "
|
|
"systemctl daemon-reload; "
|
|
"systemctl reset-failed caddy douyinweb-api douyinweb-web 2>/dev/null; "
|
|
"systemctl start seaweed-master seaweed-volume seaweed-filer seaweed-s3 frpp nginx; "
|
|
"systemctl restart douyinweb-pb douyinweb-yt; sleep 2; "
|
|
"systemctl restart douyinweb-api; sleep 6; "
|
|
"systemctl restart douyinweb-web; sleep 4; "
|
|
"systemctl restart caddy; sleep 5; "
|
|
"free -h | head -2; uptime; "
|
|
"systemctl is-active caddy nginx frpp douyinweb-api douyinweb-web douyinweb-yt douyinweb-pb; "
|
|
"ss -lntp | grep -E ':(443|80|8014|4015|4014|8020)\\b' || true",
|
|
300,
|
|
)
|
|
|
|
run(
|
|
v,
|
|
"curl -sS -m 12 http://127.0.0.1:8014/api/health | head -c 300; echo; "
|
|
"curl -sS -m 12 -o /dev/null -w 'web=%{http_code}\\n' http://127.0.0.1:4015/; "
|
|
"curl -sS -m 12 -o /dev/null -w 'yt=%{http_code}\\n' http://127.0.0.1:4015/youtube; "
|
|
"curl -sS -m 12 -o /dev/null -w 'caddy443=%{http_code}\\n' -k https://127.0.0.1/ -H 'Host: dylive.nomadro.com'; "
|
|
"wg-quick down wg-dy 2>/dev/null; wg-quick up wg-dy; sleep 2; wg show wg-dy | head -14",
|
|
60,
|
|
)
|
|
v.close()
|
|
|
|
# Physical guest via FRP
|
|
try:
|
|
g = ssh(4014, "eric", "4669805")
|
|
run(
|
|
g,
|
|
"echo 4669805 | sudo -S -p '' bash -lc '"
|
|
"wg-quick down wg-dy 2>/dev/null; wg-quick up wg-dy; sleep 2; "
|
|
"systemctl start douyinweb-api douyinweb-web; "
|
|
"wg show wg-dy | head -12; "
|
|
"curl -sS -m 8 http://127.0.0.1:8014/api/health | head -c 160; echo; "
|
|
"systemctl is-active douyinweb-api douyinweb-web"
|
|
"'",
|
|
90,
|
|
)
|
|
g.close()
|
|
except Exception as ex:
|
|
print("guest fail", ex, flush=True)
|
|
|
|
v = ssh()
|
|
run(v, "ping -c 3 -W 2 10.8.0.2 | tail -4; curl -sS -m 10 -o /dev/null -w 'wg_api=%{http_code}\\n' http://10.8.0.2:8014/api/health", 30)
|
|
v.close()
|
|
|
|
print("\n=== public ===", flush=True)
|
|
with httpx.Client(follow_redirects=False, timeout=20) as cl:
|
|
for u in [
|
|
"https://dylive.nomadro.com/api/health",
|
|
"https://dylive.nomadro.com/youtube",
|
|
"https://dy.nomadro.com/api/health",
|
|
"https://dy.nomadro.com/",
|
|
]:
|
|
try:
|
|
r = cl.get(u)
|
|
print(u, r.status_code, (r.headers.get("location") or "")[:40], flush=True)
|
|
except Exception as ex:
|
|
print(u, "ERR", ex, flush=True)
|
|
|
|
print("DONE_NUCLEAR", flush=True)
|