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
3.0 KiB
Python
92 lines
3.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Hotfix attribution + re-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", "_attr_neko.py"),
|
|
("backend/app/youtube_live.py", "/opt/douyinWEB/backend/app/youtube_live.py", "_attr_live.py"),
|
|
]
|
|
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
TS=$(date +%s)
|
|
ins(){ cp -a "$2" "$2.bak-attr-$TS" 2>/dev/null || true; install -m 644 "$1" "$2"; }
|
|
ins /tmp/_attr_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
ins /tmp/_attr_live.py /opt/douyinWEB/backend/app/youtube_live.py
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python -m py_compile app/youtube_neko.py app/youtube_live.py
|
|
echo COMPILE_OK
|
|
NEKO_BEFORE=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
NEKO_AFTER=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_BEFORE=$NEKO_BEFORE NEKO_AFTER=$NEKO_AFTER"
|
|
if [ "$NEKO_BEFORE" != "$NEKO_AFTER" ]; then
|
|
echo WARN_NEKO_CHANGED
|
|
# start any stopped without recreate
|
|
for name in $(docker ps -a --filter name=douyinweb-neko- --format '{{.Names}}'); do
|
|
st=$(docker inspect -f '{{.State.Status}}' "$name")
|
|
if [ "$st" != "running" ]; then docker start "$name" || true; fi
|
|
done
|
|
sleep 3
|
|
fi
|
|
docker ps --filter name=douyinweb-neko- --format '{{.Names}} {{.Status}}'
|
|
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/_attr_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
with sftp.file("/tmp/_probe_live_studio_guest.py", "wb") as f:
|
|
f.write((ROOT / "scripts/_probe_live_studio_guest.py").read_bytes())
|
|
sftp.close()
|
|
_, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_attr_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_live_studio_guest.py",
|
|
timeout=180,
|
|
)
|
|
print((o2.read() + e2.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|