douyinWEB/scripts/_probe_pve_vps_deploy.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

75 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
import sys, paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(host, port, user, password, cmd, timeout=60, label=""):
print(f"\n===== {label or host}:{port} =====")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
last_err = None
for u, p in [(user, password)] if isinstance(password, str) else password:
try:
c.connect(host, port, u, p, timeout=25, allow_agent=False, look_for_keys=False, banner_timeout=25)
print(f"login ok {u}@{host}:{port}")
break
except Exception as e:
last_err = e
print(f"fail {u}: {type(e).__name__} {e}")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
else:
print("CONNECT FAILED", last_err)
return None
_, o, e = c.exec_command(cmd, timeout=timeout)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
print(out[-12000:])
if err.strip():
print("STDERR", err[-1500:])
c.close()
return True
CMD_VPS = r"""
set +e
echo HOST $(hostname) $(uname -srm)
echo IP; hostname -I
uptime; free -h | head -2
echo '--- listen ---'
ss -lntp | grep -E ':(22|80|443|51820|51821|8000|8014|4015|4014)\b' || ss -lntp | head -25
echo '--- docker ---'
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' 2>/dev/null | head -20
echo '--- nginx/caddy ---'
ls /etc/nginx/sites-enabled /etc/nginx/conf.d 2>/dev/null
which caddy nginx 2>/dev/null
echo '--- dns tools ---'
which wg wg-quick 2>/dev/null
echo '--- nomadro ---'
grep -R 'nomadro' /etc/nginx /etc/caddy 2>/dev/null | head -20
"""
CMD_PVE = r"""
set +e
echo HOST $(hostname) $(uname -srm)
whoami; id
echo IP; hostname -I; ip -4 addr | grep inet
uptime; free -h | head -2
echo '--- docker ---'
which docker docker-compose 2>/dev/null
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' 2>/dev/null | head
echo '--- python/node ---'
python3 --version 2>/dev/null; node -v 2>/dev/null; npm -v 2>/dev/null
echo '--- listen ---'
ss -lntp | head -20
echo '--- wg ---'
which wg wg-quick 2>/dev/null
ls /etc/wireguard 2>/dev/null
echo '--- git/app ---'
ls /opt /home 2>/dev/null | head
"""
ssh("107.173.30.245", 22, "root", "Xiao4669805", CMD_VPS, 90, "US VPS")
# PVE ubuntu via FRP 4014
pwds = [("eric", "4669805"), ("eric", "Xiao4669805"), ("root", "Xiao4669805"), ("root", "4669805")]
ssh("107.173.30.245", 4014, "eric", pwds, CMD_PVE, 90, "PVE ubuntu via 4014")