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
2.8 KiB
Python
97 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy Studio viewer chart UI + 90pt minute reports. API restart only; no Chrome touch."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PASS = "4669805"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
FILES = [
|
|
("backend/app/youtube_neko.py", "/tmp/_viz_neko.py"),
|
|
("frontend/src/components/StudioViewerChart.tsx", "/tmp/_viz_chart.tsx"),
|
|
("frontend/src/components/YtRelayProStatusPanel.tsx", "/tmp/_viz_panel.tsx"),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
install -m 644 /tmp/_viz_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
mkdir -p /opt/douyinWEB/frontend/src/components
|
|
install -m 644 /tmp/_viz_chart.tsx /opt/douyinWEB/frontend/src/components/StudioViewerChart.tsx
|
|
install -m 644 /tmp/_viz_panel.tsx /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx
|
|
|
|
BEFORE=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
AFTER=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_BEFORE=$BEFORE NEKO_AFTER=$AFTER"
|
|
test "$BEFORE" = "$AFTER"
|
|
|
|
systemctl stop douyinweb-web || true
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-web
|
|
|
|
# Ensure reports length in snapshot
|
|
cd /opt/douyinWEB/backend
|
|
PYTHONPATH=/opt/douyinWEB/backend .venv/bin/python - <<'PY'
|
|
from app import youtube_neko as yn
|
|
for nid in range(1, 8):
|
|
n = len(yn.list_studio_minute_reports(nid, limit=90))
|
|
if n:
|
|
print(f"neko{nid} reports={n}")
|
|
print("OK")
|
|
PY
|
|
echo DEPLOY_OK
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(12):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
return 1
|
|
sftp = c.open_sftp()
|
|
for rel, tmp in FILES:
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write((ROOT / rel).read_bytes())
|
|
print("up", rel, flush=True)
|
|
with sftp.file("/tmp/_viz_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(
|
|
f"echo '{PASS}' | sudo -S -p '' bash /tmp/_viz_deploy.sh",
|
|
timeout=900,
|
|
)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-10000:] if len(out) > 10000 else out)
|
|
c.close()
|
|
return 0 if "DEPLOY_OK" in out else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|