# -*- coding: utf-8 -*- """One-shot redeploy after TS fix; never touch business data.""" import time import paramiko HOST = "107.173.30.245" REPO = "/opt/douyinWEB" BRANCH = "test1" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd: str, timeout: int = 300) -> str: _, o, e = c.exec_command(cmd, timeout=timeout) out = o.read().decode("utf-8", "replace").strip() err = e.read().decode("utf-8", "replace").strip() return (out + ("\n" + err if err else "")).strip() ts = int(time.time()) print("[backup]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_test1_{ts} && ls -lh /tmp/monitor.db.bak_test1_{ts}")) print("[fingerprint before]", run(f"stat -c '%n %s %Y' {REPO}/backend/data/monitor.db")) print("[git]", run(f"cd {REPO} && git fetch origin {BRANCH} && git pull --ff-only origin {BRANCH} && git log --oneline -2 && git status -sb")) print("[api kill+start]") print(run("systemctl kill -s SIGKILL douyinweb-api || true; systemctl reset-failed douyinweb-api || true; sleep 1; systemctl start douyinweb-api; sleep 5; systemctl is-active douyinweb-api")) print("[npm build]") print(run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -30", timeout=360)) print("[web restart]", run("systemctl restart douyinweb-web; sleep 4; systemctl is-active douyinweb-web")) print("[api]", run("systemctl is-active douyinweb-api")) print("[fingerprint after]", run(f"stat -c '%n %s %Y' {REPO}/backend/data/monitor.db")) print("[health]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/docs || true")) print("[web local]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4015/ || true")) c.close() print("DONE")