Skip to content

Commit dc14b33

Browse files
committed
System Touch
1 parent 7bc84f4 commit dc14b33

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

scripts/shutdown.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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."

0 commit comments

Comments
 (0)