diff --git a/README.md b/README.md index 1009617d..91883f22 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,12 @@ This feature can be controlled via the following variables: * `WARM_OPENAPI_ENDPOINT_URL` (enviornment variable) * Description: (24.0.0.4+) The URL to access during SCC population if WARM_OPENAPI_ENDPOINT is true. * Default: `"localhost:9080/openapi"` +* `PORT_OPEN_TIMEOUT_SECONDS` (environment variable) + * Description: The timeout in seconds to wait for the Liberty server port to open (detected via message `CWWKO0219I` in the messages log) during SCC population before exiting populate_scc. + * Default: `"30"` +* `MESSAGES_LOG_FILE` (environment variable) + * Description: The path to the Liberty server messages log file to check for port open during SCC population. + * Default: `"/logs/messages.log"` ## Logging diff --git a/ga/latest/kernel/helpers/build/configure.sh b/ga/latest/kernel/helpers/build/configure.sh index ddacb7cd..af7716dc 100755 --- a/ga/latest/kernel/helpers/build/configure.sh +++ b/ga/latest/kernel/helpers/build/configure.sh @@ -198,6 +198,12 @@ function main() { if [ ! "$WARM_OPENAPI_ENDPOINT_URL" = "" ]; then cmd+=" -o $WARM_OPENAPI_ENDPOINT_URL" fi + if [ ! "$PORT_OPEN_TIMEOUT_SECONDS" = "" ]; then + cmd+=" -r $PORT_OPEN_TIMEOUT_SECONDS" + fi + if [ ! "$MESSAGES_LOG_FILE" = "" ]; then + cmd+=" -f $MESSAGES_LOG_FILE" + fi eval $cmd fi } diff --git a/ga/latest/kernel/helpers/build/populate_scc.sh b/ga/latest/kernel/helpers/build/populate_scc.sh index a74c52a9..058adef2 100755 --- a/ga/latest/kernel/helpers/build/populate_scc.sh +++ b/ga/latest/kernel/helpers/build/populate_scc.sh @@ -33,6 +33,8 @@ WARM_ENDPOINT=true WARM_ENDPOINT_URL=localhost:9080/ WARM_OPENAPI_ENDPOINT=true WARM_OPENAPI_ENDPOINT_URL=localhost:9080/openapi +PORT_OPEN_TIMEOUT_SECONDS=${PORT_OPEN_TIMEOUT_SECONDS:-30} # Default timeout in seconds to wait for port to open. +MESSAGES_LOG_FILE=${MESSAGES_LOG_FILE:-/logs/messages.log} # Default log file location to check for port open. # If this directory exists and has at least ug=rwx permissions, assume the base image includes an SCC called 'openj9_system_scc' and build on it. # If not, build on our own SCC. @@ -63,7 +65,7 @@ CREATE_LAYER="$OPENJ9_JAVA_OPTIONS,createLayer,groupAccess" DESTROY_LAYER="$OPENJ9_JAVA_OPTIONS,destroy" PRINT_LAYER_STATS="$OPENJ9_JAVA_OPTIONS,printTopLayerStats" -while getopts ":i:s:u:o:tdhwcml" OPT +while getopts ":i:s:u:o:r:f:tdhwcml" OPT do case "$OPT" in i) @@ -97,9 +99,15 @@ do o) WARM_OPENAPI_ENDPOINT_URL="${OPTARG}" ;; + r) + PORT_OPEN_TIMEOUT_SECONDS="${OPTARG}" + ;; + f) + MESSAGES_LOG_FILE="${OPTARG}" + ;; h) echo \ -"Usage: $0 [-i iterations] [-s size] [-t] [-d] [-w] [-c] [-u url] [-m] [-l] [-o url] +"Usage: $0 [-i iterations] [-s size] [-t] [-d] [-w] [-c] [-u url] [-m] [-l] [-o url] [-r timeout_seconds] [-f log_file] -i Number of iterations to run to populate the SCC. (Default: $ITERATIONS) -s Size of the SCC in megabytes (m suffix required). (Default: $SCC_SIZE) -t Trim the SCC to eliminate most of the free space, if any. @@ -110,6 +118,8 @@ do -m Use curl/wget to warm the openapi endpoint during SCC creation. (Default: $WARM_OPENAPI_ENDPOINT) -l Do not warm the openapi endpoint during SCC creation. -o The Open API URL endpoint to warm during SCC creation. (Default: $WARM_ENDPOINT_OPENAPI_URL) + -r Timeout in seconds to wait for port to open. (Default: $PORT_OPEN_TIMEOUT_SECONDS) + -f Log file location to check for port open. (Default: $MESSAGES_LOG_FILE) Trimming enabled=$TRIM_SCC" exit 1 @@ -128,6 +138,23 @@ done OLD_UMASK=`umask` umask 002 # 002 is required to provide group rw permission to the cache when `-Xshareclasses:groupAccess` options is used +wait_for_port_open() { + local log_file="${MESSAGES_LOG_FILE}" + local timeout=${PORT_OPEN_TIMEOUT_SECONDS} + local count=0 + + while [ $count -lt $timeout ]; do + if [ -f "$log_file" ] && grep -q "CWWKO0219I" "$log_file"; then + return 0 + fi + sleep 1 + count=$((count + 1)) + done + + echo "Exiting populate_scc because port didn't open after $timeout seconds (CWWKO0219I not found in $log_file)." + exit 0 +} + # Explicity create a class cache layer for this image layer here rather than allowing # `server start` to do it, which will lead to problems because multiple JVMs will be started. java $CREATE_LAYER -Xscmx$SCC_SIZE -version @@ -136,7 +163,9 @@ if [ $TRIM_SCC == yes ] then echo "Calculating SCC layer upper bound, starting with initial size $SCC_SIZE." # Populate the newly created class cache layer. + rm -f "$MESSAGES_LOG_FILE" /opt/ibm/wlp/bin/server start + wait_for_port_open if [ ${WARM_ENDPOINT} == true ] then @@ -171,7 +200,9 @@ fi # Server start/stop to populate the /output/workarea and make subsequent server starts faster. for ((i=0; i<$ITERATIONS; i++)) do + rm -f "$MESSAGES_LOG_FILE" /opt/ibm/wlp/bin/server start + wait_for_port_open if [ ${WARM_ENDPOINT} == true ] then