douyinWEB/scripts/_pve_wg_resume.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

89 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""Resume PVE guest WireGuard client. VPS wg-dy already up. Do not restart VPS services."""
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
VPS = "107.173.30.245"
v = paramiko.SSHClient()
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
v.connect(VPS, 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False)
p = paramiko.SSHClient()
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
p.connect(VPS, 4014, "eric", "4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(c, cmd, timeout=180):
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
print("=== dylive ===")
print(run(v, "curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health; wg show wg-dy; ip -4 addr show wg-dy | head -5", 20))
print("=== PVE apt state ===")
print(run(p, "command -v wg; command -v ffmpeg; dpkg -l wireguard-tools ffmpeg python3-venv 2>/dev/null | awk '/^ii/{print $2,$3}'; ls /var/lib/dpkg/lock-frontend 2>/dev/null && echo lock_present || echo no_lock", 30))
print("=== finish apt if needed ===")
print(run(
p,
"echo '4669805' | sudo -S -p '' bash -c '"
"export DEBIAN_FRONTEND=noninteractive; "
"if ! command -v wg >/dev/null; then apt-get update -y; apt-get install -y --no-install-recommends wireguard-tools; fi; "
"if ! command -v ffmpeg >/dev/null; then apt-get install -y --no-install-recommends ffmpeg; fi; "
"if ! python3 -m venv -h >/dev/null 2>&1; then apt-get install -y --no-install-recommends python3-venv python3-pip; fi; "
"command -v wg; ffmpeg -version | head -1"
"'",
300,
))
# fetch keys already generated on VPS
keys = run(v, "echo SERVER_PUB $(cat /etc/wireguard/wg-dy.server.pub); echo PVE_PRIV $(cat /etc/wireguard/wg-dy.pve.key)")
print("keys fetched")
kv = {}
for line in keys.splitlines():
parts = line.split()
if len(parts) == 2:
kv[parts[0]] = parts[1]
pve_conf = f"""[Interface]
Address = 10.8.0.2/24
PrivateKey = {kv['PVE_PRIV']}
[Peer]
PublicKey = {kv['SERVER_PUB']}
Endpoint = 107.173.30.245:51820
AllowedIPs = 10.8.0.0/24
PersistentKeepalive = 25
"""
sftp = p.open_sftp()
with sftp.file("/tmp/wg-dy.conf", "w") as f:
f.write(pve_conf)
sftp.close()
print("=== PVE wg-quick up ===")
print(run(
p,
"echo '4669805' | sudo -S -p '' bash -c '"
"install -m 600 /tmp/wg-dy.conf /etc/wireguard/wg-dy.conf; rm -f /tmp/wg-dy.conf; "
"wg-quick down wg-dy 2>/dev/null || true; wg-quick up wg-dy; "
"systemctl enable wg-quick@wg-dy >/dev/null; wg show wg-dy; ip -4 addr show wg-dy"
"'",
40,
))
time.sleep(3)
print("=== ping ===")
print("VPS->PVE", run(v, "ping -c 4 -W 2 10.8.0.2; wg show wg-dy", 20))
print("PVE->VPS", run(p, "ping -c 4 -W 2 10.8.0.1", 20))
print("=== dylive after ===")
print(run(v, "curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health; systemctl is-active caddy sing-box docker", 20))
v.close()
p.close()