# -*- coding: utf-8 -*- """Rebuild frontend on dy.nomadro.live and restart web service.""" import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "108.174.50.68" FIX_SH = r"""#!/usr/bin/env bash set -euo pipefail cd /opt/douyinWEB/frontend echo "=== node/npm ===" node -v npm -v echo "=== clean partial .next ===" rm -rf .next echo "=== npm install ===" npm install --no-audit --no-fund echo "=== npm run build ===" npm run build echo "=== build artifacts ===" ls -la .next | head -15 test -f .next/BUILD_ID && echo BUILD_ID_OK || (echo BUILD_ID_MISSING; exit 1) systemctl restart douyinweb-web sleep 5 systemctl is-active douyinweb-web curl -sS -o /dev/null -w "web:%{http_code}\n" "http://127.0.0.1:4015/login" curl -sS -o /dev/null -w "login:%{http_code}\n" -X POST "http://127.0.0.1:8014/api/auth/login" \ -H "Content-Type: application/json" \ -d '{"username":"hackrobot","password":"Xiao4669805@"}' curl -sS -o /dev/null -w "pub:%{http_code}\n" --max-time 25 "https://dy.nomadro.live/login" curl -sS -o /dev/null -w "pub_health:%{http_code}\n" --max-time 25 "https://dy.nomadro.live/api/health" echo DONE """ def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False) remote = "/tmp/fix_dy_web.sh" sftp = c.open_sftp() with sftp.file(remote, "w") as f: f.write(FIX_SH) sftp.chmod(remote, 0o755) sftp.close() chan = c.get_transport().open_session() chan.settimeout(900) chan.get_pty(width=200, height=50) chan.exec_command(f"bash {remote}") while True: if chan.recv_ready(): print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True) if chan.recv_stderr_ready(): print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True) if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready(): break time.sleep(0.3) while chan.recv_ready(): print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True) code = chan.recv_exit_status() c.close() print(f"\nexit {code}") return code if __name__ == "__main__": raise SystemExit(main())