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>
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy round-2 response speed opts; measure hot paths on VPS."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
REPO = "/opt/douyinWEB"
|
|
|
|
FILES = [
|
|
"backend/app/main.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/shorts_pipeline.py",
|
|
"backend/app/ops_panel.py",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
"frontend/src/app/page.tsx",
|
|
"frontend/src/app/shorts/page.tsx",
|
|
]
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
|
|
print("uploaded", rel)
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
systemctl restart douyinweb-api
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl restart douyinweb-web
|
|
sleep 3
|
|
systemctl is-active douyinweb-api douyinweb-web
|
|
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
import time, json
|
|
from app.db import init_db, get_settings_map
|
|
from app.youtube_relay_pipeline import youtube_relay_pipeline as pipe
|
|
from app.shorts_pipeline import shorts_pipeline as sp
|
|
from app import ops_panel
|
|
from app.monitor import monitor as mon
|
|
|
|
init_db()
|
|
|
|
t0=time.perf_counter(); st=pipe.status(); t1=time.perf_counter()
|
|
st2=pipe.status(); t2=time.perf_counter()
|
|
blob=json.dumps(st, ensure_ascii=False)
|
|
print(f"relay_status_ms first={(t1-t0)*1000:.1f} cached={(t2-t1)*1000:.1f} json_kb={len(blob)/1024:.1f} has_entries={'entries' in st} groups={len(st.get('groups') or [])}")
|
|
|
|
t0=time.perf_counter(); ss=sp.status(); t1=time.perf_counter()
|
|
ss2=sp.status(); t2=time.perf_counter()
|
|
print(f"shorts_status_ms first={(t1-t0)*1000:.1f} cached={(t2-t1)*1000:.1f} live={ss.get('douyin_live_count')}")
|
|
|
|
t0=time.perf_counter(); op=ops_panel.snapshot(); t1=time.perf_counter()
|
|
op2=ops_panel.snapshot(); t2=time.perf_counter()
|
|
print(f"ops_snapshot_ms first={(t1-t0)*1000:.1f} cached={(t2-t1)*1000:.1f} sites={len(op.get('sites') or [])}")
|
|
|
|
t0=time.perf_counter()
|
|
cfg=get_settings_map()
|
|
m=mon.status(light=True)
|
|
t1=time.perf_counter()
|
|
print(f"health_light_ms={(t1-t0)*1000:.1f} live={m.get('live_count')} shorts={bool(cfg.get('shorts_enabled'))}")
|
|
PY
|
|
"""
|
|
print("remote deploy…")
|
|
stdin, stdout, stderr = c.exec_command(cmd, timeout=360)
|
|
out = stdout.read().decode("utf-8", "replace")
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
code = stdout.channel.recv_exit_status()
|
|
print(out)
|
|
if err.strip():
|
|
print("STDERR:", err[-2500:])
|
|
print("exit", code)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|