122 lines
3.7 KiB
Python
122 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy receiving-first Neko panel fix + douyin non-UHD to both VPS."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
|
|
PASS = "Xiao4669805"
|
|
DY, DYLIVE = "108.174.50.68", "107.173.30.245"
|
|
FILES = [
|
|
"backend/app/douyin.py",
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx",
|
|
]
|
|
|
|
|
|
def connect(host):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(12):
|
|
try:
|
|
c.connect(host, 22, "root", PASS, timeout=45, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", host, e, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
def run(c, cmd, timeout=900):
|
|
_i, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def put(c, local: Path, remote: str):
|
|
sftp = c.open_sftp()
|
|
with sftp.file(remote, "wb") as f:
|
|
f.write(local.read_bytes())
|
|
sftp.close()
|
|
|
|
|
|
for rel in FILES:
|
|
p = ROOT / rel.replace("/", "\\")
|
|
print(hashlib.sha256(p.read_bytes()).hexdigest()[:12], rel, flush=True)
|
|
|
|
print("=== dy upload+build ===", flush=True)
|
|
c = connect(DY)
|
|
for rel in FILES:
|
|
put(c, ROOT / rel.replace("/", "\\"), f"/opt/douyinWEB/{rel}")
|
|
print(
|
|
run(
|
|
c,
|
|
r"""
|
|
set -e
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app.douyin import pick_stream_candidates
|
|
room={"stream_url":{"flv_pull_url":{"ORIGIN":"http://x/a_uhd.flv","HD1":"http://x/a_hd.flv"}}}
|
|
assert 'a_hd.flv' in pick_stream_candidates(room)[0]
|
|
print('non_uhd_ok')
|
|
PY
|
|
grep -n 'YouTube 接流中\|推流接流\|receiving-first' /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx | head -10
|
|
systemctl restart douyinweb-api
|
|
cd /opt/douyinWEB/frontend
|
|
export NODE_OPTIONS=--max-old-space-size=3072
|
|
npm run build 2>&1 | tail -15
|
|
systemctl restart douyinweb-web
|
|
tar -C /opt/douyinWEB/frontend -czf /tmp/next-recv-fix.tgz .next
|
|
tar -C /opt/douyinWEB -czf /tmp/src-recv-fix.tgz \
|
|
backend/app/douyin.py \
|
|
frontend/src/components/YtRelayProStatusPanel.tsx
|
|
ls -lh /tmp/next-recv-fix.tgz /tmp/src-recv-fix.tgz
|
|
systemctl is-active douyinweb-api douyinweb-web
|
|
""",
|
|
timeout=800,
|
|
),
|
|
flush=True,
|
|
)
|
|
sftp = c.open_sftp()
|
|
sftp.get("/tmp/next-recv-fix.tgz", str(ROOT / "scripts/_next-recv-fix.tgz"))
|
|
sftp.get("/tmp/src-recv-fix.tgz", str(ROOT / "scripts/_src-recv-fix.tgz"))
|
|
sftp.close()
|
|
c.close()
|
|
|
|
print("=== dylive sync ===", flush=True)
|
|
c = connect(DYLIVE)
|
|
put(c, ROOT / "scripts/_src-recv-fix.tgz", "/tmp/src-recv-fix.tgz")
|
|
put(c, ROOT / "scripts/_next-recv-fix.tgz", "/tmp/next-recv-fix.tgz")
|
|
print(
|
|
run(
|
|
c,
|
|
r"""
|
|
set -e
|
|
tar -C /opt/douyinWEB -xzf /tmp/src-recv-fix.tgz
|
|
systemctl restart douyinweb-api
|
|
systemctl stop douyinweb-web || true
|
|
rm -rf /opt/douyinWEB/frontend/.next.bak_recv
|
|
mv /opt/douyinWEB/frontend/.next /opt/douyinWEB/frontend/.next.bak_recv 2>/dev/null || true
|
|
tar -C /opt/douyinWEB/frontend -xzf /tmp/next-recv-fix.tgz
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-api douyinweb-web
|
|
python3 - <<'PY'
|
|
import hashlib, pathlib
|
|
for rel in ['backend/app/douyin.py','frontend/src/components/YtRelayProStatusPanel.tsx']:
|
|
p=pathlib.Path('/opt/douyinWEB')/rel
|
|
print(hashlib.sha256(p.read_bytes()).hexdigest()[:12], rel)
|
|
PY
|
|
grep -n 'YouTube 接流中\|推流接流' /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx | head -5
|
|
""",
|
|
timeout=120,
|
|
),
|
|
flush=True,
|
|
)
|
|
c.close()
|
|
print("ALL_DONE", flush=True)
|