douyinWEB/scripts/_finish_ops_modal_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

48 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""Safe code-only deploy for /ops site detail modal."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
DB = f"{REPO}/backend/data/monitor.db"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd: str, timeout: int = 420) -> str:
_, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace").strip()
print("=== SAFE DEPLOY ops modal ===")
before = run(f"stat -c '%s' {DB}")
print("[db]", before)
dirty = run(f"cd {REPO} && git diff --name-only")
if dirty.strip():
print("[stash]", run(f"cd {REPO} && git stash push -m auto-before-ops-modal -- {dirty.replace(chr(10), ' ')}"))
print("[pull]", run(f"cd {REPO} && git pull --ff-only origin test1 && git log --oneline -1"))
run("systemctl restart douyinweb-api")
for i in range(30):
if run("systemctl is-active douyinweb-api", timeout=15) == "active":
print("[api] active")
break
time.sleep(2)
build = run(f"cd {REPO}/frontend && npm run build", timeout=360)
for line in build.splitlines()[-10:]:
print(line.encode("ascii", "replace").decode("ascii"))
run("systemctl restart douyinweb-web")
time.sleep(3)
after = run(f"stat -c '%s' {DB}")
print("[db after]", after, "delta", int(after) - int(before) if before.isdigit() and after.isdigit() else "?")
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
c.close()
print("DONE")