Files

39 lines
1.1 KiB
Python
Raw Permalink Normal View History

2026-06-24 13:11:34 +08:00
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)
def run(cmd, desc=""):
if desc:
print(f"[{desc}]")
stdin, stdout, stderr = c.exec_command(cmd, timeout=15)
time.sleep(1)
ch = stdout.channel
out = b""
while not ch.exit_status_ready():
if ch.recv_ready():
out += ch.recv(4096)
time.sleep(0.2)
while ch.recv_ready():
out += ch.recv(4096)
print(f" {out.decode().strip()[:300]}")
# 检查容器
run(f"cd {NAS_DEPLOY_PATH} && {COMPOSE} ps", "容器状态")
# 检查后端日志
run(f"cd {NAS_DEPLOY_PATH} && {COMPOSE} logs backend --tail=10", "后端日志")
# 检查问卷 API
run("curl -s http://localhost:8080/api/questionnaires | head -c 500", "问卷API")
c.close()