douyinWEB/scripts/_diag_phys_neko_untouched.py
2026-09-13 22:10:49 -05:00

85 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""READ-ONLY: check if physical neko containers/profiles were touched."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(port, user, pw):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(
"107.173.30.245",
port,
user,
pw,
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
return c
except Exception as ex:
print("retry", port, i, ex, flush=True)
time.sleep(3)
raise SystemExit(f"ssh {port} fail")
def run(c, cmd, t=90):
_i, o, e = c.exec_command(cmd, timeout=t)
o.channel.recv_exit_status()
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
print("===== PHYSICAL (4014) READ-ONLY =====", flush=True)
p = ssh(4014, "eric", "4669805")
run(
p,
r"""
echo '4669805' | sudo -S -p '' bash -lc '
set +e
echo "--- docker neko/ops CreatedAt / Status (no changes) ---"
docker ps -a --filter name=douyinweb-neko --filter name=douyinweb-ops-neko \
--format "table {{.Names}}\t{{.Status}}\t{{.CreatedAt}}"
echo "--- profile mtimes (assign + ops) ---"
ls -la --time-style=long-iso /opt/douyinWEB/backend/data/neko/profiles/ 2>/dev/null | head -20
ls -la --time-style=long-iso /opt/douyinWEB/backend/data/ops_neko/profiles/ 2>/dev/null | head -20
echo "--- recent docker events for neko (last 2h) ---"
docker events --since 2h --until 0s --filter type=container 2>/dev/null | grep -iE "neko|ops-neko" | tail -40
echo "--- last journal docker/api touching neko ---"
journalctl -u douyinweb-api --since "2 hours ago" --no-pager 2>/dev/null | grep -iE "neko|force-recreate|compose" | tail -30
echo "--- container start times ---"
for c in douyinweb-ops-neko-1 douyinweb-ops-neko-2 douyinweb-neko-1 douyinweb-neko-3; do
echo "== $c =="
docker inspect "$c" --format "StartedAt={{.State.StartedAt}} FinishedAt={{.State.FinishedAt}} Running={{.State.Running}} RestartCount={{.RestartCount}}" 2>/dev/null
done
'
""",
)
p.close()
print("===== VPS: confirm we only touched VPS neko =====", flush=True)
v = ssh(22, "root", "Xiao4669805")
run(
v,
r"""
set +e
echo '--- VPS local neko ---'
docker ps -a --filter name=douyinweb-neko --format 'table {{.Names}}\t{{.Status}}\t{{.CreatedAt}}\t{{.Ports}}' | head -20
echo '--- frp-aux (remapped 1920x) ---'
systemctl is-active dy-frp-http-aux
grep -oE '1920[0-7]|920[0-7]' /etc/systemd/system/dy-frp-http-aux.service | sort | uniq -c
echo '--- dy.com neko1 upstream ---'
grep -A2 'handle_path /neko/1/\*' /etc/caddy/sites/dy.nomadro.com.caddy | head -5
""",
)
v.close()
print("DONE", flush=True)