38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
|
import paramiko, time
|
||
|
|
|
||
|
|
NAS_HOST = "100.85.152.112"
|
||
|
|
NAS_PORT = 22
|
||
|
|
NAS_USER = "simon"
|
||
|
|
NAS_PASS = "Nas82829330"
|
||
|
|
|
||
|
|
def exec_and_read(c, cmd, wait=3):
|
||
|
|
stdin, stdout, stderr = c.exec_command(cmd)
|
||
|
|
time.sleep(wait)
|
||
|
|
while not stdout.channel.exit_status_ready():
|
||
|
|
time.sleep(0.2)
|
||
|
|
out = stdout.read().decode("utf-8", errors="replace")
|
||
|
|
err = stderr.read().decode("utf-8", errors="replace")
|
||
|
|
return out, err
|
||
|
|
|
||
|
|
def main():
|
||
|
|
c = paramiko.SSHClient()
|
||
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
|
|
c.connect(NAS_HOST, NAS_PORT, NAS_USER, NAS_PASS, timeout=15)
|
||
|
|
|
||
|
|
docker = "echo 'Nas82829330' | sudo -S /usr/local/bin/docker"
|
||
|
|
path = "/volume1/docker/gaokao-portal"
|
||
|
|
|
||
|
|
# 检查后端日志
|
||
|
|
out, err = exec_and_read(c, f"cd {path} && {docker} compose logs backend --tail=30", wait=5)
|
||
|
|
print("=== 后端日志 ===")
|
||
|
|
print(out[:1500])
|
||
|
|
|
||
|
|
# 检查 nginx 日志
|
||
|
|
out, err = exec_and_read(c, f"cd {path} && {docker} compose logs nginx --tail=10", wait=3)
|
||
|
|
print("\n=== Nginx 日志 ===")
|
||
|
|
print(out[:800])
|
||
|
|
|
||
|
|
c.close()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|