88 lines
2.7 KiB
Python
88 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""dylive-only: upload key-visible files, restart API, copy .next from local tgz if present / skip heavy build."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PASS = "Xiao4669805"
|
|
FILES = [
|
|
"backend/app/yt_assign_db.py",
|
|
"backend/app/yt_stream_key_db.py",
|
|
"backend/app/youtube_relay_status.py",
|
|
"backend/app/main.py",
|
|
"frontend/src/lib/ytRelayStatus.ts",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
"frontend/src/app/youtube/keys/page.tsx",
|
|
"frontend/src/app/youtube-relay-log/page.tsx",
|
|
]
|
|
|
|
|
|
def connect():
|
|
last = None
|
|
for i in range(15):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=300,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
last = e
|
|
print("retry", i, e, flush=True)
|
|
time.sleep(5 + i * 2)
|
|
raise SystemExit(last)
|
|
|
|
|
|
c = connect()
|
|
_i, o, e = c.exec_command(
|
|
"docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort; free -h | head -2",
|
|
timeout=60,
|
|
)
|
|
before = (o.read() + e.read()).decode()
|
|
print("BEFORE\n", before, flush=True)
|
|
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
remote = f"/opt/douyinWEB/{rel}"
|
|
_i, o, e = c.exec_command(f"mkdir -p {'/'.join(remote.split('/')[:-1])}", timeout=30)
|
|
o.channel.recv_exit_status()
|
|
print("put", rel, flush=True)
|
|
sftp.put(str(ROOT / rel), remote)
|
|
sftp.close()
|
|
|
|
_i, o, e = c.exec_command(
|
|
r"""
|
|
set -euo pipefail
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python -c 'from app import yt_assign_db; gs=yt_assign_db.list_groups(include_urls=False, include_secret=True); print("keys", sum(1 for g in gs if g.get("stream_key")))'
|
|
systemctl restart douyinweb-api
|
|
sleep 5
|
|
systemctl is-active douyinweb-api
|
|
# Avoid next build OOM — only restart web (src already updated; if build missing keys route, page may 404 until later build)
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-web
|
|
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort
|
|
curl -sk -o /dev/null -w 'keys:%{http_code}\n' https://dylive.nomadro.com/youtube/keys
|
|
""",
|
|
timeout=120,
|
|
)
|
|
print((o.read() + e.read()).decode(), flush=True)
|
|
c.close()
|
|
print("DONE_DYLIVE")
|