import paramiko import sys import time sys.stdout.reconfigure(encoding="utf-8", errors="replace") 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, t: int = 120) -> str: _, o, e = c.exec_command(cmd, timeout=t) return (o.read() + e.read()).decode("utf-8", "replace") print("=== PULL ===") print( run( "cd /opt/douyinWEB && GIT_TERMINAL_PROMPT=0 git pull origin dev && git log --oneline -3", t=180, ) ) print("=== CHECK ===") print(run("test -f /opt/douyinWEB/frontend/src/app/x/XOpsPanels.tsx && echo HAS_PANELS || echo MISSING")) print(run("grep -n 'X 运营控制台' /opt/douyinWEB/frontend/src/app/x/page.tsx | head -2")) print("=== API ===") run("systemctl restart douyinweb-api") time.sleep(5) print(run("systemctl is-active douyinweb-api")) print("=== BUILD ===") run( "cd /opt/douyinWEB/frontend && npm run build > /tmp/dylive_fe_build.log 2>&1; echo EXIT:$? >> /tmp/dylive_fe_build.log", t=420, ) print(run("tail -n 30 /tmp/dylive_fe_build.log")) print("=== WEB ===") run("systemctl restart douyinweb-web") time.sleep(5) print(run("systemctl is-active douyinweb-api; systemctl is-active douyinweb-web")) print(run("cd /opt/douyinWEB && git log --oneline -1")) print("DEPLOY_DONE") c.close()