feat(deploy): add script to kill processes on Next.js deployment ports

This commit is contained in:
2026-06-17 19:39:41 +08:00
parent c7975a7aaf
commit bb40f3c042
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
# Kill processes listening on the Next.js test/main deployment ports.
PORTS="9135 9185"
find_pids_by_port() {
port="$1"
if command -v lsof >/dev/null 2>&1; then
lsof -ti tcp:"$port" 2>/dev/null || true
return
fi
if command -v fuser >/dev/null 2>&1; then
fuser "$port"/tcp 2>/dev/null || true
return
fi
echo "WARN: neither lsof nor fuser is available; cannot inspect port $port" >&2
}
kill_port() {
port="$1"
pids="$(find_pids_by_port "$port")"
if [ -z "$pids" ]; then
echo "port $port: no process found"
return
fi
echo "port $port: stopping PID(s) $pids"
kill $pids 2>/dev/null || true
sleep 2
still_running=""
for pid in $pids; do
if kill -0 "$pid" 2>/dev/null; then
still_running="$still_running $pid"
fi
done
if [ -n "$still_running" ]; then
echo "port $port: force killing PID(s)$still_running"
kill -9 $still_running 2>/dev/null || true
fi
}
for port in $PORTS; do
kill_port "$port"
done