From b08c9fc1418f2226efee91f01396aeba92b4c9a0 Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Fri, 10 May 2024 15:26:08 +0100 Subject: [PATCH] [OPENJDK-2968] move ARGS/OPTS handling to run-java.sh Move the handling of JAVA_OPTIONS, JAVA_OPTS and suffixing of JAVA_ARGS onto the command line, as well as dispatching to an application-supplied run script, from s2i/run to run-java.sh. This is to make this logic available to the runtime images. Signed-off-by: Jonathan Dowland --- .../opt/jboss/container/java/run/run-java.sh | 21 ++++++++++++++++++- modules/s2i/bash/artifacts/usr/local/s2i/run | 19 ++++++----------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/modules/run/artifacts/opt/jboss/container/java/run/run-java.sh b/modules/run/artifacts/opt/jboss/container/java/run/run-java.sh index 5dc154fe..b0fc9d15 100644 --- a/modules/run/artifacts/opt/jboss/container/java/run/run-java.sh +++ b/modules/run/artifacts/opt/jboss/container/java/run/run-java.sh @@ -227,6 +227,16 @@ function configure_passwd() { fi } +handle_java_options() { + # JAVA_OPTIONS is a deprecated name for JAVA_OPTS. It is not supported + # in the images from UBI9 onwards. + if [ -z "${JAVA_OPTS+isunset}" ] && [ -n "${JAVA_OPTIONS+isset}" ]; then + JAVA_OPTS="$JAVA_OPTIONS" + fi + export JAVA_OPTS + export JAVA_OPTIONS="$JAVA_OPTS" +} + # Start JVM startup() { # Initialize environment @@ -251,4 +261,13 @@ startup() { # ============================================================================= # Fire up -startup $* + +handle_java_options + +if [ -f "${S2I_TARGET_DEPLOYMENTS_DIR}/bin/run.sh" ]; then + echo "Starting the application using the bundled ${S2I_TARGET_DEPLOYMENTS_DIR}/bin/run.sh ..." + exec ${DEPLOYMENTS_DIR}/bin/run.sh $* ${JAVA_ARGS} +else + echo "Starting the Java application using ${JBOSS_CONTAINER_JAVA_RUN_MODULE}/run-java.sh $*..." + startup $* ${JAVA_ARGS} +fi diff --git a/modules/s2i/bash/artifacts/usr/local/s2i/run b/modules/s2i/bash/artifacts/usr/local/s2i/run index fe99ab23..97b32f57 100644 --- a/modules/s2i/bash/artifacts/usr/local/s2i/run +++ b/modules/s2i/bash/artifacts/usr/local/s2i/run @@ -11,10 +11,6 @@ source "${JBOSS_CONTAINER_JAVA_S2I_MODULE}/s2i-core-hooks" # Global S2I variable setup s2i_core_env_init -if [ -z "${JAVA_OPTS+isunset}" ] && [ -n "${JAVA_OPTIONS+isset}" ]; then - JAVA_OPTS="$JAVA_OPTIONS" -fi - if [ -f "${JBOSS_CONTAINER_JOLOKIA_MODULE}/jolokia-opts" ]; then # Always include jolokia-opts, which can be empty if switched off via env S2I_RUN_OPTS="${S2I_RUN_OPTS} $(${JBOSS_CONTAINER_JOLOKIA_MODULE}/jolokia-opts)" @@ -24,13 +20,10 @@ if [ -f "${JBOSS_CONTAINER_PROMETHEUS_MODULE}/prometheus-opts" ]; then fi export S2I_RUN_OPTS -export JAVA_OPTS -export JAVA_OPTIONS="$JAVA_OPTS" -if [ -f "${S2I_TARGET_DEPLOYMENTS_DIR}/bin/run.sh" ]; then - echo "Starting the application using the bundled ${S2I_TARGET_DEPLOYMENTS_DIR}/bin/run.sh ..." - exec ${DEPLOYMENTS_DIR}/bin/run.sh $args ${JAVA_ARGS} -else - echo "Starting the Java application using ${JBOSS_CONTAINER_JAVA_RUN_MODULE}/run-java.sh $args..." - exec "${JBOSS_CONTAINER_JAVA_RUN_MODULE}/run-java.sh" $args ${JAVA_ARGS} -fi +# XXX this is needed to support a user-provided alternative run script but we +# should probably export all relevant S2I variables, possibly by moving the +# above `source` statements into run-java.sh +export S2I_TARGET_DEPLOYMENTS_DIR + +exec "${JBOSS_CONTAINER_JAVA_RUN_MODULE}/run-java.sh" $args