douyinWEB/scripts/_deploy_signed_out_ui.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

95 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy signed-out detection + UI (no Chrome restart)."""
from __future__ import annotations
import time
from pathlib import Path
import paramiko
PASS = "4669805"
ROOT = Path(__file__).resolve().parents[1]
FILES = [
("backend/neko/cdp_studio_scrape.py", "/opt/douyinWEB/backend/neko/cdp_studio_scrape.py", "_so_scrape.py"),
("backend/app/youtube_neko.py", "/opt/douyinWEB/backend/app/youtube_neko.py", "_so_neko.py"),
(
"backend/app/youtube_relay_pipeline.py",
"/opt/douyinWEB/backend/app/youtube_relay_pipeline.py",
"_so_pipe.py",
),
(
"frontend/src/components/YtRelayProStatusPanel.tsx",
"/opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx",
"_so_pro.tsx",
),
]
SH = r"""#!/bin/bash
set -euo pipefail
install -m 644 /tmp/_so_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
install -m 644 /tmp/_so_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
install -m 644 /tmp/_so_pipe.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
install -m 644 /tmp/_so_pro.tsx /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx
cd /opt/douyinWEB/backend && .venv/bin/python -m py_compile app/youtube_neko.py app/youtube_relay_pipeline.py
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"
# NO chrome restart
systemctl stop douyinweb-web || true
cd /opt/douyinWEB/frontend && npm run build
systemctl start douyinweb-web
sleep 2
systemctl is-active douyinweb-web
echo BUILD_OK
python3 - <<'PY'
import subprocess
from pathlib import Path
script = Path('/opt/douyinWEB/backend/neko/cdp_studio_scrape.py').read_text(encoding='utf-8')
p = subprocess.run(['docker','exec','-i','douyinweb-neko-1','python3','-'], input=script, capture_output=True, text=True, timeout=30)
print((p.stdout or p.stderr or '')[-300:])
PY
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(10):
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__)
time.sleep(2)
else:
return 1
sftp = c.open_sftp()
for rel, _dst, tmp in FILES:
with sftp.file(f"/tmp/{tmp}", "wb") as f:
f.write((ROOT / rel).read_bytes())
print("up", rel)
with sftp.file("/tmp/_so_deploy.sh", "w") as f:
f.write(SH)
sftp.close()
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_so_deploy.sh", timeout=600)
print((o.read() + e.read()).decode("utf-8", "replace")[-12000:])
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())