#!/usr/bin/env bash # The whole precedence question, asked once with every source set at the same time. # # demo.greeting is set by application.yaml, by application-prod.yaml, by an environment # variable, by a system property and by a command-line argument -- simultaneously. The # endpoint reports all of them in order, so the winner is not a matter of opinion. set -euo pipefail set +m # no job-control notices ("Killed") in the captured transcript cd "$(dirname "$0")/.." source scripts/env.sh { echo "== every source sets demo.greeting at once ==" echo echo "\$ DEMO_GREETING=from-environment-variable \\" echo " java -Ddemo.greeting=from-system-property \\" echo " -jar $JAR --spring.profiles.active=prod \\" echo " --demo.greeting=from-command-line-argument" echo scripts/stop.sh DEMO_GREETING=from-environment-variable setsid nohup java \ -Ddemo.greeting=from-system-property -jar "$JAR" \ --spring.profiles.active=prod --demo.greeting=from-command-line-argument \ > /tmp/profiles-precedence.log 2>&1 < /dev/null & echo $! > target/app.pid for _ in $(seq 1 60); do curl -s -o /dev/null "http://127.0.0.1:${APP_PORT}/precedence" && break; sleep 1; done curl -s "http://127.0.0.1:${APP_PORT}/precedence?name=demo.greeting" | python3 -m json.tool echo echo "== and with the environment variable removed, nothing else changed ==" scripts/stop.sh setsid nohup java -Ddemo.greeting=from-system-property -jar "$JAR" \ --spring.profiles.active=prod > /tmp/profiles-precedence2.log 2>&1 < /dev/null & echo $! > target/app.pid for _ in $(seq 1 60); do curl -s -o /dev/null "http://127.0.0.1:${APP_PORT}/precedence" && break; sleep 1; done curl -s "http://127.0.0.1:${APP_PORT}/precedence?name=demo.greeting" | python3 -m json.tool scripts/stop.sh } > docs/output/01-precedence.txt 2>&1 cat docs/output/01-precedence.txt