Files

29 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs the demo once, in the foreground, streaming to both stdout and a log file.
#
# scripts/run.sh <db-name> <shards-dir> [grid-size] [pool-size] [extra java -D or --args...]
#
# Never `pkill -f 'spring-boot'` here -- the pattern matches this script's own invocation line
# under some shells and can kill the wrong process. Kill by main class instead.
set -eu
DB_NAME="${1:?usage: run.sh <db-name> <shards-dir> [grid-size] [pool-size] [extra args...]}"
SHARDS_DIR="${2:?usage: run.sh <db-name> <shards-dir> [grid-size] [pool-size] [extra args...]}"
GRID_SIZE="${3:-4}"
POOL_SIZE="${4:-4}"
shift $(( $# >= 4 ? 4 : $# ))
for p in $(ps -eo pid,cmd | grep '[P]artitioningDemoApplication' | awk '{print $1}'); do
kill -9 "$p" 2>/dev/null || true
done
JAR="$(dirname "$0")/../target/spring-batch-partitioning-1.0.0.jar"
LOG="/tmp/run-${DB_NAME}.log"
"${JAVA_HOME:?set JAVA_HOME}/bin/java" -jar "$JAR" \
--spring.datasource.url="jdbc:h2:file:./data/${DB_NAME};AUTO_SERVER=TRUE" \
--partition.shards-dir="$SHARDS_DIR" \
--partition.grid-size="$GRID_SIZE" \
--partition.pool-core-size="$POOL_SIZE" \
--partition.pool-max-size="$POOL_SIZE" \
"$@" 2>&1 | tee "$LOG"