# -*- coding: utf-8 -*- import time import paramiko HOST = "107.173.30.245" USER = "root" PASSWORD = "Xiao4669805" def run(c, cmd, timeout=420): print("$", cmd[:160], flush=True) chan = c.get_transport().open_session() chan.settimeout(timeout) chan.get_pty() chan.exec_command(cmd) buf = [] while True: if chan.recv_ready(): buf.append(chan.recv(65535).decode("utf-8", "replace")) if chan.exit_status_ready() and not chan.recv_ready(): break time.sleep(0.25) while chan.recv_ready(): buf.append(chan.recv(65535).decode("utf-8", "replace")) code = chan.recv_exit_status() print("".join(buf)[-2500:], flush=True) return code def main(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, USER, PASSWORD, timeout=60, banner_timeout=60, allow_agent=False, look_for_keys=False) # Finish frontend build + restart if previous run was interrupted mid-build run(c, "pgrep -af 'npm run build' || true") if run(c, "cd /opt/douyinWEB/frontend && npm run build", timeout=420) != 0: raise SystemExit(1) run( c, "systemctl restart douyinweb-web --no-block; sleep 4; " "systemctl start douyinweb-api douyinweb-web; sleep 2; " "systemctl is-active douyinweb-api douyinweb-web caddy seaweed-s3", ) run(c, "grep DY_S3_PUBLIC /etc/systemd/system/douyinweb-api.service") run(c, "curl -s http://127.0.0.1:8014/api/health") run( c, "curl -sI 'https://s3.nomadro.com/douyin-covers/covers/93680996-cafa-430b-8951-842624b46230.jpg' | head -n 16", ) run( c, "curl -s -o /dev/null -w 'object:%{http_code} size:%{size_download} time:%{time_total}\\n' " "'https://s3.nomadro.com/douyin-covers/covers/93680996-cafa-430b-8951-842624b46230.jpg'", ) c.close() print("DONE") if __name__ == "__main__": main()