72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Deploy P0 telemetry/gate fixes — in-place overwrite, restart API only."""
|
|
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]
|
|
FILES = [
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/main.py",
|
|
"backend/neko/live-ops-extension/background.js",
|
|
"backend/neko/live-ops-extension/content.js",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/ops_neko.py",
|
|
"backend/neko/cdp_studio_scrape.py",
|
|
]
|
|
|
|
|
|
def deploy(host: str, port: int, user: str, pw: str, sudo: bool) -> None:
|
|
print(f"\n===== {user}@{host}:{port} =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
sftp = c.open_sftp()
|
|
pairs = []
|
|
for rel in FILES:
|
|
local = ROOT / rel
|
|
tmp = f"/tmp/_p0_{rel.replace('/', '_')}"
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write(local.read_bytes())
|
|
pairs.append((tmp, f"/opt/douyinWEB/{rel}"))
|
|
print("upload", rel)
|
|
sh = ["#!/bin/bash", "set -e"]
|
|
for tmp, dst in pairs:
|
|
sh.append(f"mkdir -p \"$(dirname '{dst}')\"")
|
|
sh.append(f"cp -a '{dst}' \"{dst}.bak.p0_$(date +%Y%m%d_%H%M%S)\" 2>/dev/null || true")
|
|
sh.append(f"cat '{tmp}' > '{dst}'")
|
|
sh.append(f"echo updated {dst}")
|
|
sh.append("systemctl restart douyinweb-api || systemctl restart douyinweb || true")
|
|
sh.append("sleep 3")
|
|
sh.append("systemctl is-active douyinweb-api || systemctl is-active douyinweb || true")
|
|
sh.append("curl -sS -m 5 http://127.0.0.1:8014/api/health | head -c 120; echo")
|
|
# sanity: mirror helper present
|
|
sh.append("grep -n 'Never invent' /opt/douyinWEB/backend/app/youtube_neko.py | head -2")
|
|
sh.append("grep -n 'dylive.nomadro.com' /opt/douyinWEB/backend/neko/live-ops-extension/background.js | head -2")
|
|
with sftp.file("/tmp/_deploy_p0_telemetry.sh", "w") as f:
|
|
f.write("\n".join(sh) + "\n")
|
|
sftp.close()
|
|
cmd = (
|
|
f"echo '{pw}' | sudo -S -p '' bash /tmp/_deploy_p0_telemetry.sh"
|
|
if sudo
|
|
else "bash /tmp/_deploy_p0_telemetry.sh"
|
|
)
|
|
_i, o, e = c.exec_command(cmd, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
def main() -> None:
|
|
deploy("107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|
|
deploy("107.173.30.245", 4014, "eric", "4669805", sudo=True)
|
|
print("\nDone. No Chrome restart (login safe). Extension picks dylive on next SW/content cycle.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|