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>
103 lines
2.8 KiB
Python
103 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
VPS = "107.173.30.245"
|
|
GUEST_PW = "4669805"
|
|
VPS_PW = "Xiao4669805"
|
|
|
|
START_PY = r"""
|
|
import os, sys
|
|
sys.path.insert(0, "/opt/douyinWEB/backend")
|
|
os.chdir("/opt/douyinWEB/backend")
|
|
os.environ.setdefault("DY_NEKO_EDGE_UPSTREAM", "10.8.0.2")
|
|
os.environ.setdefault("DY_NEKO_NAT1TO1", "107.173.30.245")
|
|
os.environ.setdefault("DY_PUBLIC_BASE_URL", "https://dy.nomadro.com")
|
|
from app import youtube_neko
|
|
print("docker", youtube_neko._docker_available())
|
|
print("assets", youtube_neko.status_summary(desired=1).get("assets"))
|
|
print("starting...")
|
|
r = youtube_neko.instance_action(1, "start")
|
|
print("start", r)
|
|
print("caddy", youtube_neko.sync_caddy_neko_snippet(4))
|
|
"""
|
|
|
|
|
|
def ssh(host, port, user, password, tries=8):
|
|
last = None
|
|
for i in range(tries):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
host,
|
|
port,
|
|
user,
|
|
password,
|
|
timeout=60,
|
|
banner_timeout=90,
|
|
auth_timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
return c
|
|
except Exception as ex:
|
|
last = ex
|
|
print(f"ssh fail{i} {type(ex).__name__}", flush=True)
|
|
time.sleep(2 + i)
|
|
raise last # type: ignore[misc]
|
|
|
|
|
|
def run(c, cmd, timeout=300):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
g = ssh(VPS, 4014, "eric", GUEST_PW)
|
|
sftp = g.open_sftp()
|
|
with sftp.file("/tmp/_start_neko1.py", "w") as f:
|
|
f.write(START_PY)
|
|
sftp.close()
|
|
|
|
print("=== start ===", flush=True)
|
|
out = run(
|
|
g,
|
|
f"echo '{GUEST_PW}' | sudo -S -p '' "
|
|
"/opt/douyinWEB/backend/.venv/bin/python /tmp/_start_neko1.py",
|
|
360,
|
|
)
|
|
print(out, flush=True)
|
|
|
|
print("=== docker/http ===", flush=True)
|
|
print(
|
|
run(
|
|
g,
|
|
f"echo '{GUEST_PW}' | sudo -S -p '' bash -lc "
|
|
"'docker ps -a --filter name=douyinweb-neko --format \"{{{{.Names}}}} {{{{.Status}}}}\"; "
|
|
"curl -sS -m 8 -o /dev/null -w local9200:%{{http_code}}\\\\n http://127.0.0.1:9200/; "
|
|
"journalctl -u docker --no-pager -n 5 2>/dev/null | tail -5 || true'",
|
|
40,
|
|
),
|
|
flush=True,
|
|
)
|
|
g.close()
|
|
|
|
v = ssh(VPS, 22, "root", VPS_PW)
|
|
print(
|
|
run(
|
|
v,
|
|
"curl -sS -m 12 -o /dev/null -w 'neko1:%{http_code}\\n' https://dy.nomadro.com/neko/1/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'wg:%{http_code}\\n' http://10.8.0.2:9200/; "
|
|
"curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health",
|
|
30,
|
|
),
|
|
flush=True,
|
|
)
|
|
v.close()
|