File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # shutdown.sh — gracefully stop the WebExpress server and all related connections
3+
4+ PORTS=(49152 49155 5512 6682)
5+
6+ echo " [shutdown] Closing server ports: ${PORTS[*]} "
7+
8+ for PORT in " ${PORTS[@]} " ; do
9+ # collect every PID listening on this port
10+ PIDS=$( lsof -ti TCP:" $PORT " 2> /dev/null)
11+ if [ -n " $PIDS " ]; then
12+ echo " [shutdown] Sending SIGTERM to PIDs on port $PORT : $PIDS "
13+ kill -TERM $PIDS 2> /dev/null
14+ fi
15+ done
16+
17+ # allow a brief grace period for clean shutdown
18+ sleep 2
19+
20+ for PORT in " ${PORTS[@]} " ; do
21+ PIDS=$( lsof -ti TCP:" $PORT " 2> /dev/null)
22+ if [ -n " $PIDS " ]; then
23+ echo " [shutdown] Sending SIGKILL to remaining PIDs on port $PORT : $PIDS "
24+ kill -KILL $PIDS 2> /dev/null
25+ fi
26+ done
27+
28+ echo " [shutdown] Done."
You can’t perform that action at this time.
0 commit comments