From 9fc015b4a1867d5b452d5e6304b9ae174ec29dfe Mon Sep 17 00:00:00 2001 From: Jeff Nelson Date: Sun, 18 Jan 2026 11:06:13 -0500 Subject: [PATCH] duplicate some functionality of the concourse script to the .env script --- concourse-server/scripts/.env | 74 ++++++++++++++++++++++++++++++ concourse-server/scripts/concourse | 5 +- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/concourse-server/scripts/.env b/concourse-server/scripts/.env index 8b67d622c..c9fd02bfa 100644 --- a/concourse-server/scripts/.env +++ b/concourse-server/scripts/.env @@ -92,7 +92,81 @@ cd "$(dirname "$0")" APP_HOME="`pwd -P`/.." cd $APP_HOME + +# Parse the java_home value from configuration sources. +# Checks in priority order (lowest to highest): +# 1. concourse.prefs (file) +# 2. concourse.yaml (file) +# 3. concourse.prefs.dev (file) +# 4. concourse.yaml.dev (file) +# 5. CONCOURSE_JAVA_HOME (environment variable) - highest priority +# Supports both prefs format (key = value) and YAML format (key: value). +# Matches key names case-insensitively: java_home, javaHome, java-home +# +# @return the configured java_home value, or empty string if not configured +parse_java_home_from_config() { + # NOTE: This is a brittle approximation of how the more robust config CLI + # parses this value for the concourse script. Here, we cannot use the + # config CLI because it sources this file. So, this is a rudimentary + # attempt to bootstrap the right java configuration in as similar a way + # as possible as concourse does it + local config_dir="$APP_HOME/conf" + local java_home_value="" + + # Config files in priority order (lowest to highest) + local config_files=( + "concourse.prefs" + "concourse.yaml" + "concourse.prefs.dev" + "concourse.yaml.dev" + ) + + # Pattern to match java_home, javaHome, or java-home (case-insensitive) + local key_pattern='^(java_home|javaHome|java-home)\s*' + + for file in "${config_files[@]}"; do + local filepath="$config_dir/$file" + if [ -f "$filepath" ]; then + local value="" + if [[ "$file" == *.yaml ]]; then + # YAML format: key: /path/to/java + value=$(grep -iE "${key_pattern}:" "$filepath" 2>/dev/null | head -n1 | sed 's/^[^:]*:[[:space:]]*//' | xargs) + else + # Prefs format: key = /path/to/java + value=$(grep -iE "${key_pattern}=" "$filepath" 2>/dev/null | head -n1 | sed 's/^[^=]*=[[:space:]]*//' | xargs) + fi + # Only update if we found a non-empty value (higher priority overrides) + if [ -n "$value" ]; then + java_home_value="$value" + fi + fi + done + + # Environment variable has highest priority (matches config CLI behavior) + if [ -n "$CONCOURSE_JAVA_HOME" ]; then + java_home_value="$CONCOURSE_JAVA_HOME" + fi + + echo "$java_home_value" +} + + # Determine the Java command to use to start the JVM. +# First check for configured java_home, then fall back to detection. +JAVA_HOME_PREF=$(parse_java_home_from_config) + +if [ -n "$JAVA_HOME_PREF" ]; then + # Use configured java_home + if [ -d "$JAVA_HOME_PREF" ]; then + JAVA_HOME="$JAVA_HOME_PREF"; export JAVA_HOME + else + die "ERROR: java_home is set to an invalid directory: $JAVA_HOME_PREF + +Please verify the path exists and contains a valid Java installation." + fi +fi + +# Set JAVACMD based on JAVA_HOME (configured or from environment) if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables diff --git a/concourse-server/scripts/concourse b/concourse-server/scripts/concourse index e0306edb0..459af0101 100755 --- a/concourse-server/scripts/concourse +++ b/concourse-server/scripts/concourse @@ -289,7 +289,10 @@ CLASSPATH="$APP_HOME/lib/*" configure(){ echo "Loading Concourse Server configuration..." CONFIG_SCRIPT=$BIN_DIR"/config" - CONFIG=`exec $CONFIG_SCRIPT view -k jmx_port -k remote_debugger_port -k heap_size -k log_level -k force_g1gc -k java_home` + CONFIG=$(exec $CONFIG_SCRIPT view -k jmx_port -k remote_debugger_port -k heap_size -k log_level -k force_g1gc -k java_home 2>&1) || { + echo "$CONFIG" >&2 + exit 1 + } #jmx_port JMX_PREF=`echo "$CONFIG" | grep -e '^jmx_port\s*=\s*[0-9]\{1,\}$' | head -n1 | cut -d'=' -f2 | tr -d ' '`