douyinWEB/scripts/_finish_xclips_deploy.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

52 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
"""Finish x-clips deploy after safe pull (API restart + frontend build)."""
from __future__ import annotations
import time
import paramiko
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd: str, timeout: int = 360) -> str:
_, out, err = c.exec_command(cmd, timeout=timeout)
o = out.read().decode("utf-8", "replace")
e = err.read().decode("utf-8", "replace")
return (o + e).strip()
print("tip:", run(f"cd {REPO} && git log -1 --format=%h%x20%s"))
for i in range(25):
st = run("systemctl is-active douyinweb-api")
print("api", i, st)
if st == "active":
break
if st in {"failed", "inactive"}:
run("systemctl restart douyinweb-api")
time.sleep(2)
print("npm build...")
print(
run(
f"cd {REPO}/frontend && npm run build > /tmp/fe_build_xclips.log 2>&1; "
"echo EXIT:$?; tail -n 20 /tmp/fe_build_xclips.log",
timeout=360,
)
)
c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5)
time.sleep(6)
print("web:", run("systemctl is-active douyinweb-web"))
print("api:", run("systemctl is-active douyinweb-api"))
print("probe:", run("curl -sS -m 10 http://127.0.0.1:8014/api/x-clips/status | head -c 500"))
print("db:", run(f"stat -c '%n %s %Y' {REPO}/backend/data/monitor.db"))
c.close()
print("DONE")