# -*- coding: utf-8 -*- from __future__ import annotations import sys import time import paramiko 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, timeout: int = 360) -> str: _, out, err = c.exec_command(cmd, timeout=timeout) return (out.read() + err.read()).decode("utf-8", "replace").strip() print(run("cd /opt/douyinWEB && git pull --ff-only origin test1 && git log -1 --format=%h")) c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5) for i in range(20): st = run("systemctl is-active douyinweb-api") print("api", i, st) if st == "active": break time.sleep(2) print( run( "cd /opt/douyinWEB && /opt/douyinWEB/backend/.venv/bin/python -c " "\"from backend.app.x_clips_pipeline import build_caption; from backend.app import db; " "cfg=db.get_settings_map(); " "print(repr(cfg.get('x_clips_caption_template'))); " "print(repr(build_caption({'anchor_name':'xiaoxia'}, cfg)))\"" ) ) print(run("cd /opt/douyinWEB/frontend && npm run build > /tmp/fe_cap.log 2>&1; echo EXIT:$?; tail -n 5 /tmp/fe_cap.log | tr -cd '\\11\\12\\15\\40-\\176'", timeout=360)) c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5) time.sleep(5) print("web", run("systemctl is-active douyinweb-web")) c.close()