#!/usr/bin/env bash # Starts one replica on a given port and stage, and waits for it to report healthy. # Usage: start-instance.sh set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$DIR/env.sh" PORT="$1" STAGE="$2" # -XX:TieredStopAtLevel=1 and a small fixed heap cut this JVM's own startup CPU # burst dramatically (C2 compilation and heap sizing are the two biggest costs of a # cold Spring Boot start). That matters here specifically because two replicas share # a 2-core sandbox: a slow-starting replica can starve its own sibling's health # checks long enough to look like an outage that never actually happened - see # docs/11-the-load-generator.md. nohup java -XX:TieredStopAtLevel=1 -XX:+UseSerialGC -Xms128m -Xmx256m \ -jar "$JAR" --server.port="$PORT" --app.stage="$STAGE" \ > "$EC_LOG_DIR/instance-$PORT.log" 2>&1 < /dev/null & echo $! > "$EC_PID_DIR/$PORT.pid" echo "started stage $STAGE on port $PORT (pid $(cat "$EC_PID_DIR/$PORT.pid"))" wait_healthy "$PORT" echo "port $PORT healthy"