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

79 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Read-only inventory of services on dy.nomadro.live."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "108.174.50.68"
PASS = "Xiao4669805"
def run(c, cmd, timeout=60):
print(f"\n===== {cmd[:90]} =====", flush=True)
_i, o, e = c.exec_command(cmd, timeout=timeout)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
if out:
sys.stdout.write(out)
if err and err.strip():
sys.stdout.write("[stderr]\n" + err)
sys.stdout.flush()
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
print(f"ssh {HOST} try {i}...", flush=True)
c.connect(HOST, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
print("ssh ok", flush=True)
break
except Exception as e:
print(f"fail: {e}", flush=True)
time.sleep(1 + i)
else:
raise SystemExit("ssh_fail")
run(c, "hostname; uptime; free -h; nproc; cat /etc/os-release | head -4")
run(c, "systemctl list-units --type=service --state=running --no-pager --no-legend | sort")
run(
c,
"systemctl list-unit-files --type=service --state=enabled --no-pager --no-legend 2>/dev/null | "
"awk '{print $1}' | sort | head -120",
)
run(
c,
"for u in douyinweb-api douyinweb-web nginx caddy docker containerd "
"sing-box frpp 'wg-quick@wg-dy' 'wg-quick@wg-dy-cn' seaweedfs seaweed "
"redis redis-server postgresql mysql mongod; do "
"printf '%-28s %s\\n' \"$u\" \"$(systemctl is-active \"$u\" 2>/dev/null || echo n/a)\"; done",
)
run(
c,
"ss -lntp 2>/dev/null | head -80 || netstat -lntp 2>/dev/null | head -80",
)
run(
c,
"docker ps --format 'table {{.Names}}\\t{{.Status}}\\t{{.Ports}}' 2>/dev/null || echo 'no docker'",
)
run(
c,
"ps aux --sort=-%cpu | head -25; echo '---MEM---'; ps aux --sort=-%mem | head -15",
)
run(
c,
"systemctl list-units --type=service --state=failed --no-pager --no-legend || true; "
"echo '---'; ls /etc/systemd/system/*.service 2>/dev/null | xargs -n1 basename | sort",
)
c.close()
print("\nDONE", flush=True)
if __name__ == "__main__":
main()