# -*- coding: utf-8 -*- import paramiko REMOTE_SH = r"""#!/bin/bash set -e cd /opt/douyinWEB/frontend npm run build >/tmp/fe_cont.log 2>&1 && echo FE_OK || { tail -40 /tmp/fe_cont.log; echo FE_FAIL; exit 1; } systemctl restart douyinweb-yt douyinweb-api douyinweb-web sleep 4 systemctl is-active douyinweb-yt systemctl is-active douyinweb-api systemctl is-active douyinweb-web for i in 1 2 3 4 5 6 7 8 9 10; do code=$(curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x) echo health=$code if [ "$code" = "200" ]; then break; fi sleep 2 done """ c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=30) sftp = c.open_sftp() with sftp.file("/tmp/_fe_phys.sh", "w") as f: f.write(REMOTE_SH) sftp.close() _, o, e = c.exec_command("echo '4669805' | sudo -S -p '' bash /tmp/_fe_phys.sh", timeout=900) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err.strip(): print(err[-800:]) c.close()