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>
97 lines
3.2 KiB
Python
97 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy next round of assign/Neko reliability fixes."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "108.174.50.68"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
APP = "/opt/douyinWEB"
|
|
FILES = [
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/yt_assign_db.py",
|
|
"backend/app/main.py",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
]
|
|
|
|
REMOTE = r"""#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
source /etc/douyinweb.env 2>/dev/null || true
|
|
export DY_PUBLIC_BASE_URL="${DY_PUBLIC_BASE_URL:-${PUBLIC_BASE:-https://dy.nomadro.live}}"
|
|
export DY_NEKO_NAT1TO1="${DY_NEKO_NAT1TO1:-108.174.50.68}"
|
|
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app import yt_assign_db, youtube_neko
|
|
groups = yt_assign_db.list_groups(include_urls=False, include_secret=False)
|
|
assert all("stream_key" not in g for g in groups), "list leaked stream_key"
|
|
print("list_ok", len(groups), "no_stream_key")
|
|
# stop non-enabled neko instances (default OFF)
|
|
r = youtube_neko.sync_for_groups(groups)
|
|
print("sync", {k: r.get(k) for k in ("ok","started","stopped","created","compose_up")})
|
|
st = youtube_neko.status_summary(desired=0)
|
|
for i in st.get("instances") or []:
|
|
print("inst", i["id"], i.get("status"), "run", i.get("running"), "url", i.get("studio_url"))
|
|
if groups:
|
|
g = yt_assign_db.get_group(groups[0]["id"], include_secret=True)
|
|
print("get_has_key", "stream_key" in (g or {}), "masked_list", groups[0].get("stream_key_masked"))
|
|
PY
|
|
|
|
# nginx / neko health
|
|
curl -sS -o /dev/null -w 'nginx_neko1=%{http_code}\n' -k https://127.0.0.1/neko/1/ -H 'Host: dy.nomadro.live' || true
|
|
ss -ulnp | grep -E ':52300|:52000' | head -3 || true
|
|
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-web
|
|
echo DONE
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
print("upload", rel)
|
|
sftp.put(str(ROOT / rel), f"{APP}/{rel}")
|
|
with sftp.file("/tmp/deploy_opt2.sh", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.chmod("/tmp/deploy_opt2.sh", 0o755)
|
|
sftp.close()
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(900)
|
|
chan.get_pty(width=160, height=40)
|
|
chan.exec_command("bash /tmp/deploy_opt2.sh")
|
|
while True:
|
|
if chan.recv_ready():
|
|
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
if chan.recv_stderr_ready():
|
|
print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
|
|
break
|
|
time.sleep(0.25)
|
|
while chan.recv_ready():
|
|
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
code = chan.recv_exit_status()
|
|
c.close()
|
|
print("\nexit", code)
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|