#!/usr/bin/env bash # Shared helpers for the live scripts. Source this, do not run it. set -uo pipefail cd "$(dirname "$0")/.." JAR=target/log4j2-levels-1.0.0.jar PID="" start_app() { # start_app [spring args...] local port=$1 log=$2; shift 2 setsid nohup java -jar "$JAR" --server.port="$port" "$@" > "$log" 2>&1 < /dev/null & PID=$! for _ in $(seq 1 60); do curl -s --noproxy '*' -o /dev/null "localhost:$port/actuator/health" && return 0 kill -0 "$PID" 2>/dev/null || return 1 sleep 1 done return 1 } stop_app() { [ -n "$PID" ] && kill "$PID" 2>/dev/null && wait "$PID" 2>/dev/null PID="" } # Print the console lines written since the last call (our pattern has no timestamp). new_lines() { # new_lines local log=$1 seen=${SEEN:-0} total total=$(wc -l < "$log") tail -n +"$((seen + 1))" "$log" SEEN=$total } http() { # http [json body] -> "status body" local method=$1 port=$2 path=$3 body=${4:-} if [ -n "$body" ]; then curl -s --noproxy '*' -X "$method" -H 'Content-Type: application/json' -d "$body" -w ' [HTTP %{http_code}]' "localhost:$port$path" else curl -s --noproxy '*' -X "$method" -w ' [HTTP %{http_code}]' "localhost:$port$path" fi }