Files
spring-boot-demo/scripts/run-all.sh
Ankur Mhatre 4b6cefa60a Spring Boot 4 Actuator in production: endpoints, security, custom health indicators
Companion repository for the ankurm.com article. Every transcript in docs/output/
was produced by running this project; scripts/run-all.sh regenerates all of them.

Verified against Spring Boot 4.1.1 / Framework 7.0.9 / Security 7.1.1 /
Micrometer 1.17.1 / kafka-clients 4.2.1 on Temurin JDK 25.0.4.1+1.
2026-09-04 10:40:04 +05:30

71 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerate every file in docs/output/ from scratch.
#
# JAVA_HOME=/path/to/jdk25 ./scripts/run-all.sh
#
# Each scenario starts a fresh JVM, runs its probes, and stops it. Timing figures vary between
# machines; the status codes and bodies do not.
set -uo pipefail
cd "$(dirname "$0")/.."
: "${JAVA_HOME:?set JAVA_HOME to a JDK 25+ installation}"
export PATH="$JAVA_HOME/bin:$PATH"
JAR=target/actuator-production-1.0.0.jar
[ -f "$JAR" ] || mvn -B -q -DskipTests package
HEAP="${HEAP:--Xmx384m}"
APP_PID=""
start() { # $1 profiles, rest: extra --args
local profiles="$1"; shift
java $HEAP -jar "$JAR" --spring.profiles.active="$profiles" "$@" > /tmp/actuator-demo.log 2>&1 &
APP_PID=$!
local port=8080 url="http://127.0.0.1:8080/orders/count"
for _ in $(seq 1 90); do
c=$(curl -s -o /dev/null -w '%{http_code}' -u ops:ops-password "$url" || true)
[ -n "$c" ] && [ "$c" != "000" ] && return 0
sleep 1
done
echo "FAILED TO START (profiles=$profiles)" >&2; tail -30 /tmp/actuator-demo.log >&2; return 1
}
stop() {
[ -n "$APP_PID" ] && kill -9 "$APP_PID" 2>/dev/null
wait "$APP_PID" 2>/dev/null
APP_PID=""
for _ in $(seq 1 40); do
(exec 3<>/dev/tcp/127.0.0.1/8080) 2>/dev/null || break
sleep 0.25
done
exec 3<&- 2>/dev/null || true
}
trap stop EXIT
mkdir -p docs/output
scripts/demo-versions.sh
start "" && { scripts/demo-default-exposure.sh; stop; }
start "exposeall,open" && { scripts/demo-endpoint-catalogue.sh;
scripts/demo-open-actuator.sh; stop; }
start "exposeall,open" --management.endpoint.heapdump.access=unrestricted \
&& { scripts/demo-heapdump-leak.sh; stop; }
start "secured" && { scripts/demo-secured.sh; stop; }
start "details" && { scripts/demo-custom-health.sh;
scripts/demo-slow-indicator.sh;
scripts/demo-kafka-timeout.sh tuned; stop; }
start "details,kafkanaive" && { scripts/demo-kafka-timeout.sh naive; stop; }
start "groups" && { scripts/demo-groups-probes.sh; stop; }
# The management-port scenario readies on a different URL, so it is started by hand.
java $HEAP -jar "$JAR" --spring.profiles.active=mgmtport > /tmp/actuator-demo.log 2>&1 &
APP_PID=$!
for _ in $(seq 1 90); do
c=$(curl -s -o /dev/null -w '%{http_code}' -u ops:ops-password http://127.0.0.1:9001/manage/health || true)
[ -n "$c" ] && [ "$c" != "000" ] && break
sleep 1
done
scripts/demo-management-port.sh
stop
echo
echo "docs/output/ regenerated:"
ls -1 docs/output/