#!/usr/bin/env bash # Build and start the demo app in the foreground (or detached with -d). # Usage: scripts/run.sh [-d] set -euo pipefail cd "$(dirname "$0")/.." for p in $(ps -eo pid,cmd | grep '[j]fr-demo.jar' | awk '{print $1}'); do echo "killing previous instance: $p" kill -9 "$p" done mvn -q -B -DskipTests package if [[ "${1:-}" == "-d" ]]; then setsid nohup java -jar target/jfr-demo.jar > /tmp/jfr-demo.log 2>&1 < /dev/null & echo "started detached, pid $!" for i in $(seq 1 30); do code=$(curl -s -o /dev/null -w '%{http_code}' localhost:8080/api/jfr/recordings || true) [[ "$code" == "200" ]] && { echo "up after ${i}s"; exit 0; } sleep 1 done echo "app did not come up in time, see /tmp/jfr-demo.log" >&2 exit 1 else exec java -jar target/jfr-demo.jar fi