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>
99 lines
3.2 KiB
Python
99 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy CDP DOM scrape + probe (no docker recreate / 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/app/youtube_neko.py", "/opt/douyinWEB/backend/app/youtube_neko.py", "_cdp_neko.py"),
|
|
("backend/app/youtube_live.py", "/opt/douyinWEB/backend/app/youtube_live.py", "_cdp_live.py"),
|
|
(
|
|
"backend/neko/cdp_studio_scrape.py",
|
|
"/opt/douyinWEB/backend/neko/cdp_studio_scrape.py",
|
|
"_cdp_scrape.py",
|
|
),
|
|
(
|
|
"scripts/_probe_telemetry_detail.py",
|
|
"/tmp/_probe_telemetry_detail.py",
|
|
"_probe_telemetry_detail.py",
|
|
),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
TS=$(date +%s)
|
|
ins(){ cp -a "$2" "$2.bak-cdp-$TS" 2>/dev/null || true; install -m 644 "$1" "$2"; }
|
|
ins /tmp/_cdp_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
ins /tmp/_cdp_live.py /opt/douyinWEB/backend/app/youtube_live.py
|
|
ins /tmp/_cdp_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python -m py_compile app/youtube_neko.py app/youtube_live.py
|
|
echo COMPILE_OK
|
|
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"
|
|
if [ "$BEFORE" != "$AFTER" ]; then
|
|
for name in $(docker ps -a --filter name=douyinweb-neko- --format '{{.Names}}'); do
|
|
st=$(docker inspect -f '{{.State.Status}}' "$name")
|
|
[ "$st" = "running" ] || docker start "$name" || true
|
|
done
|
|
fi
|
|
# smoke one scrape
|
|
docker cp /opt/douyinWEB/backend/neko/cdp_studio_scrape.py douyinweb-neko-1:/tmp/cdp_studio_scrape.py
|
|
docker exec douyinweb-neko-1 python3 /tmp/cdp_studio_scrape.py | tail -c 400; echo
|
|
echo API_OK
|
|
"""
|
|
|
|
|
|
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/_cdp_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_cdp_deploy.sh", timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
_, o2, e2 = c.exec_command(
|
|
f"echo '{PASS}' | sudo -S -p '' /opt/douyinWEB/backend/.venv/bin/python /tmp/_probe_telemetry_detail.py",
|
|
timeout=300,
|
|
)
|
|
print((o2.read() + e2.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|