84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Fast emergency revive: dylive local + wg-dy bounce. No long probes."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh(port, user, pw, tries=8):
|
|
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=30,
|
|
banner_timeout=90,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
print(f"ok :{port} try={i}", flush=True)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"retry :{port} {i} {ex}", flush=True)
|
|
time.sleep(3)
|
|
raise SystemExit(f"fail :{port} {last}")
|
|
|
|
|
|
def run(c, cmd, t=60):
|
|
print(f"$ {cmd[:180]}", 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[-4000:] if out else f"(empty code={code})", flush=True)
|
|
return code
|
|
|
|
|
|
# 1) VPS: kill hung restarts lightly, start essentials only
|
|
v = ssh(22, "root", "Xiao4669805")
|
|
run(
|
|
v,
|
|
"uptime; free -h | head -2; "
|
|
"systemctl start caddy nginx frpp docker; "
|
|
"systemctl start douyinweb-api douyinweb-web douyinweb-yt douyinweb-pb; "
|
|
"systemctl is-active caddy douyinweb-api douyinweb-web",
|
|
45,
|
|
)
|
|
run(v, "wg-quick down wg-dy >/dev/null 2>&1; wg-quick up wg-dy; sleep 1; wg show wg-dy | head -12", 40)
|
|
run(v, "curl -sS -m 8 http://127.0.0.1:8014/api/health | head -c 180; echo", 20)
|
|
v.close()
|
|
|
|
# 2) Physical guest via FRP
|
|
try:
|
|
g = ssh(4014, "eric", "4669805")
|
|
run(
|
|
g,
|
|
"echo 4669805 | sudo -S -p '' bash -lc '"
|
|
"wg-quick down wg-dy >/dev/null 2>&1; wg-quick up wg-dy; "
|
|
"systemctl start douyinweb-api douyinweb-web; "
|
|
"sleep 2; wg show wg-dy | head -10; "
|
|
"curl -sS -m 8 http://127.0.0.1:8014/api/health | head -c 120; echo; "
|
|
"systemctl is-active douyinweb-api douyinweb-web"
|
|
"'",
|
|
70,
|
|
)
|
|
g.close()
|
|
except Exception as ex:
|
|
print("guest err", ex, flush=True)
|
|
|
|
# 3) tunnel check from VPS
|
|
v = ssh(22, "root", "Xiao4669805")
|
|
run(v, "ping -c 2 -W 2 10.8.0.2 | tail -3; curl -sS -m 8 -o /dev/null -w 'wg_api=%{http_code}\\n' http://10.8.0.2:8014/api/health; curl -sS -m 8 -o /dev/null -w 'local=%{http_code}\\n' http://127.0.0.1:8014/api/health", 30)
|
|
v.close()
|
|
print("DONE_FAST", flush=True)
|