#!/usr/bin/env bash # Stop the demo application. # # This uses a PID file rather than a pattern match, deliberately. `pkill -f spring-boot` # matches the shell that is running the script and takes the terminal with it. Even a # careful-looking `ps | grep '[c]onfiguration-properties'` matches the shell's own command # line whenever that string appears in the command you just typed -- which it does, because # you typed the jar name. Killing a recorded PID cannot misfire. set -u cd "$(dirname "$0")/.." PIDFILE="${PIDFILE:-target/app.pid}" if [ -f "$PIDFILE" ]; then pid=$(cat "$PIDFILE") # Confirm the PID is still ours before signalling it: PIDs are reused. if [ -n "$pid" ] && grep -qa "configuration-properties" "/proc/$pid/cmdline" 2>/dev/null; then kill -9 "$pid" 2>/dev/null || true fi rm -f "$PIDFILE" fi # Killing the process is not the same as the socket closing, and a stale listener looks # exactly like your configuration change having had no effect. for _ in $(seq 1 40); do if ! (exec 3<>/dev/tcp/127.0.0.1/"${APP_PORT:-8080}") 2>/dev/null; then break; fi sleep 0.25 done exec 3<&- 2>/dev/null || true