Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions concourse-server/scripts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion concourse-server/scripts/concourse
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' '`
Expand Down