import paramiko, time NAS_HOST = "100.85.152.112" NAS_PORT = 22 NAS_USER = "simon" NAS_PASS = "Nas82829330" NAS_DEPLOY_PATH = "/volume1/docker/gaokao-portal" DOCKER = f"echo '{NAS_PASS}' | sudo -S /usr/local/bin/docker" COMPOSE = f"{DOCKER} compose" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(NAS_HOST, NAS_PORT, NAS_USER, NAS_PASS, timeout=20) # 1. 检查后端容器状态 def shell(cmd): transport = c.get_transport() ch = transport.open_session() ch.get_pty() ch.exec_command(cmd) out = b"" while True: if ch.recv_ready(): out += ch.recv(4096) if ch.exit_status_ready(): break time.sleep(0.3) while ch.recv_ready(): out += ch.recv(4096) return out.decode() print(shell(f"{DOCKER} {COMPOSE} ps")) # 2. 检查后端日志 print("\n--- 后端日志 ---") print(shell(f"{COMPOSE} logs backend | tail -30")) # 3. 测试 API print("\n--- API 测试 ---") print(shell("curl -v http://localhost:8080/api/questionnaires")) # 4. 测试 nginx print("\n--- Nginx 测试 ---") print(shell("curl -s http://localhost:8080/ | head -20")) c.close()