Avoid remote pnpm build overload; document health/ntfy/Kuma anchors for miniprogram smoke. Co-authored-by: Cursor <cursoragent@cursor.com>
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Kill stuck next build on server and restore nomadro.service."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
|
|
|
|
|
|
def connect(retries=8):
|
|
last = None
|
|
for i in range(retries):
|
|
try:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
HOST,
|
|
username=USER,
|
|
password=PASS,
|
|
timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
last = e
|
|
print(f"connect fail {i+1}: {e}", flush=True)
|
|
time.sleep(8)
|
|
raise last # type: ignore
|
|
|
|
|
|
def main() -> int:
|
|
c = connect()
|
|
cmd = r"""
|
|
set +e
|
|
echo '--- before ---'
|
|
ps -eo pid,etime,cmd | grep -E 'next|node.*build|pnpm' | grep -v grep | head -30
|
|
# kill build children under /var/www/nomadro.cn
|
|
pkill -f 'next build' || true
|
|
pkill -f 'pnpm build' || true
|
|
# don't kill the running production next server if possible — restart service after
|
|
sleep 2
|
|
sudo systemctl restart nomadro.service
|
|
sleep 5
|
|
systemctl is-active nomadro.service
|
|
echo '--- after ---'
|
|
ps -eo pid,etime,cmd | grep -E 'next|node|pnpm' | grep -v grep | head -20
|
|
curl -s -o /dev/null -w 'local_root:%{http_code}\n' -m 15 http://127.0.0.1:4003/ || echo local_root:ERR
|
|
curl -s -o /dev/null -w 'local_health:%{http_code}\n' -m 15 http://127.0.0.1:4003/api/health || echo local_health:ERR
|
|
echo DONE
|
|
"""
|
|
_, stdout, _ = c.exec_command(cmd, timeout=120, get_pty=True)
|
|
print(stdout.read().decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|