170 lines
5.8 KiB
Python
170 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Recover dy + dylive only. NEVER start Neko/docker containers."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
VPS = ("107.173.30.245", 22, "root", "Xiao4669805")
|
|
GUEST = ("107.173.30.245", 4014, "eric", "4669805")
|
|
|
|
|
|
def ssh(host, port, user, pw, tries=15):
|
|
last = None
|
|
for i in range(tries):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
host,
|
|
port,
|
|
user,
|
|
pw,
|
|
timeout=40,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
print(f"ssh {host}:{port} ok try={i}", flush=True)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"ssh {host}:{port} retry {i} {type(ex).__name__}: {ex}", flush=True)
|
|
time.sleep(4)
|
|
raise SystemExit(f"ssh fail {host}:{port}: {last}")
|
|
|
|
|
|
def run(c, cmd, t=180, label=""):
|
|
print(f"\n[{label}]$ {cmd[:240]}", 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")
|
|
if out.strip():
|
|
print(out[-6500:] if len(out) > 6500 else out, flush=True)
|
|
print(f"[{label}]→{code}", flush=True)
|
|
return code, out
|
|
|
|
|
|
def probe():
|
|
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(f"{u} -> {r.status_code} loc={(r.headers.get('location') or '')[:50]}", flush=True)
|
|
except Exception as ex:
|
|
print(f"{u} ERR {ex}", flush=True)
|
|
|
|
|
|
def main() -> int:
|
|
v = ssh(*VPS)
|
|
try:
|
|
# 1) Ensure Docker/Neko stay DOWN (no containers started)
|
|
run(
|
|
v,
|
|
"systemctl stop docker.socket docker containerd 2>/dev/null || true; "
|
|
"pkill -9 -f dockerd 2>/dev/null || true; "
|
|
"pkill -9 -f containerd-shim 2>/dev/null || true; "
|
|
"pkill -9 chrome 2>/dev/null || true; "
|
|
"pkill -9 chromium 2>/dev/null || true; "
|
|
"sleep 2; free -h | head -2; uptime; "
|
|
"ps aux | grep -E '[c]hrome|[d]ockerd|[n]eko' | wc -l",
|
|
t=90,
|
|
label="stop-docker-neko",
|
|
)
|
|
|
|
# 2) Core site services only
|
|
run(
|
|
v,
|
|
"mkdir -p /etc/systemd/system/caddy.service.d; "
|
|
"printf '[Service]\\nTimeoutStartSec=300\\n' > /etc/systemd/system/caddy.service.d/timeout.conf; "
|
|
"systemctl daemon-reload; "
|
|
"systemctl reset-failed caddy douyinweb-api douyinweb-web 2>/dev/null || true; "
|
|
"systemctl start seaweed-master seaweed-volume seaweed-filer seaweed-s3 frpp nginx 2>/dev/null || true; "
|
|
"systemctl start douyinweb-pb douyinweb-yt; sleep 2; "
|
|
"systemctl start douyinweb-api; sleep 8; "
|
|
"systemctl start douyinweb-web; sleep 4; "
|
|
"systemctl start caddy; sleep 4; "
|
|
"systemctl is-active caddy nginx frpp douyinweb-api douyinweb-web douyinweb-yt douyinweb-pb docker; "
|
|
"ss -lntp | grep -E ':(443|80|8014|4015|4014|8020)\\b' || true; "
|
|
"free -h | head -2; uptime",
|
|
t=320,
|
|
label="start-core",
|
|
)
|
|
|
|
run(
|
|
v,
|
|
"curl -sS -m 15 http://127.0.0.1:8014/api/health | head -c 280; 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 'caddy_dylive=%{http_code}\\n' -k -H 'Host: dylive.nomadro.com' https://127.0.0.1/api/health",
|
|
t=50,
|
|
label="local-check",
|
|
)
|
|
|
|
# 3) WG for dy.nomadro.com (edge only; do not touch Neko)
|
|
run(
|
|
v,
|
|
"systemctl start 'wg-quick@wg-dy' 2>/dev/null || true; "
|
|
"wg-quick down wg-dy 2>/dev/null || true; "
|
|
"wg-quick up wg-dy; sleep 2; "
|
|
"wg show wg-dy | head -16",
|
|
t=45,
|
|
label="wg-vps",
|
|
)
|
|
finally:
|
|
v.close()
|
|
|
|
# 4) Physical guest via FRP — start app only, no neko
|
|
try:
|
|
g = ssh(*GUEST)
|
|
try:
|
|
run(
|
|
g,
|
|
"echo 4669805 | sudo -S -p '' bash -lc '"
|
|
"wg-quick down wg-dy 2>/dev/null || true; "
|
|
"wg-quick up wg-dy; sleep 2; "
|
|
"systemctl start douyinweb-api douyinweb-web; sleep 3; "
|
|
"wg show wg-dy | head -14; "
|
|
"systemctl is-active douyinweb-api douyinweb-web; "
|
|
"curl -sS -m 10 http://127.0.0.1:8014/api/health | head -c 200; echo"
|
|
"'",
|
|
t=100,
|
|
label="guest",
|
|
)
|
|
finally:
|
|
g.close()
|
|
except Exception as ex:
|
|
print(f"guest FRP unavailable: {ex}", flush=True)
|
|
|
|
v = ssh(*VPS)
|
|
try:
|
|
run(
|
|
v,
|
|
"ping -c 3 -W 2 10.8.0.2 | tail -5; "
|
|
"curl -sS -m 12 -o /dev/null -w 'via_wg=%{http_code}\\n' http://10.8.0.2:8014/api/health; "
|
|
"systemctl is-active docker || true",
|
|
t=40,
|
|
label="tunnel-check",
|
|
)
|
|
finally:
|
|
v.close()
|
|
|
|
probe()
|
|
print("\nDONE recover (neko left stopped)", flush=True)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|