From bb40f3c0429b8508e177bbd0c7251a0293919c24 Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 19:39:41 +0800 Subject: [PATCH] feat(deploy): add script to kill processes on Next.js deployment ports --- scripts/deploy/kill_next_ports.sh | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 scripts/deploy/kill_next_ports.sh diff --git a/scripts/deploy/kill_next_ports.sh b/scripts/deploy/kill_next_ports.sh new file mode 100755 index 00000000..1006ec80 --- /dev/null +++ b/scripts/deploy/kill_next_ports.sh @@ -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