From 9414e03e1747ad593a8c3b67bbc6cee403028461 Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Thu, 25 Aug 2022 12:35:10 -0400 Subject: [PATCH 1/4] Use mv while updating situational configuration files to improve concurrency --- .../main/resources/scripts/livenessProbe.sh | 6 ++--- .../src/main/resources/scripts/startServer.sh | 21 +---------------- operator/src/main/resources/scripts/utils.sh | 23 ++++++++++++++++++- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/operator/src/main/resources/scripts/livenessProbe.sh b/operator/src/main/resources/scripts/livenessProbe.sh index fd0b4f5ba1c..868e096d119 100755 --- a/operator/src/main/resources/scripts/livenessProbe.sh +++ b/operator/src/main/resources/scripts/livenessProbe.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2017, 2021, Oracle and/or its affiliates. +# Copyright (c) 2017, 2022, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. # Kubernetes periodically calls this liveness probe script to determine whether @@ -35,9 +35,9 @@ if [ ! "${DYNAMIC_CONFIG_OVERRIDE:-notset}" = notset ]; then tgt_file=$tgt_dir/$tgt_file # add back in tgt dir path [ -f "$tgt_file" ] && [ -z "$(diff $local_fname $tgt_file 2>&1)" ] && continue # nothing changed trace "Copying file '$local_fname' to '$tgt_file'." - cp $local_fname $tgt_file # TBD ignore any error? + copyIfChanged $local_fname $tgt_file if [ -O "$tgt_file" ]; then - chmod 770 $tgt_file # TBD ignore any error? + chmod 770 $tgt_file fi done for local_fname in ${tgt_dir}/*.xml ; do diff --git a/operator/src/main/resources/scripts/startServer.sh b/operator/src/main/resources/scripts/startServer.sh index 323b600d84e..f717fb58627 100755 --- a/operator/src/main/resources/scripts/startServer.sh +++ b/operator/src/main/resources/scripts/startServer.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright (c) 2017, 2021, Oracle and/or its affiliates. +# Copyright (c) 2017, 2022, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. # @@ -29,25 +29,6 @@ fi exportInstallHomes # -# Define helper fn to copy a file only if src & tgt differ -# - -function copyIfChanged() { - [ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1 - if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then - trace "Copying '$1' to '$2'." - cp $1 $2 - [ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop - if [ -O "$2" ]; then - chmod 770 $2 - [ $? -ne 0 ] && trace SEVERE "failed chmod 770 $2" && exitOrLoop - fi - else - trace "Skipping copy of '$1' to '$2' -- these files already match." - fi -} - -# # if the auxiliary image feature is active, verify the mount, and log mount information # checkAuxiliaryImage || exitOrLoop diff --git a/operator/src/main/resources/scripts/utils.sh b/operator/src/main/resources/scripts/utils.sh index 3cb32eb7e34..a63dc976608 100755 --- a/operator/src/main/resources/scripts/utils.sh +++ b/operator/src/main/resources/scripts/utils.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2017, 2021, Oracle and/or its affiliates. +# Copyright (c) 2017, 2022, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. set -o pipefail @@ -17,6 +17,27 @@ source ${SCRIPTPATH}/utils_base.sh # [ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1 # +# +# Define helper fn to copy a file only if src & tgt differ +# + +function copyIfChanged() { + [ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1 + if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then + trace "Copying '$1' to '$2'." + tmp_file=$(mktemp -p $(dirname $1)) + cp $1 tmp_file + mv tmp_file $2 + [ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop + if [ -O "$2" ]; then + chmod 770 $2 + [ $? -ne 0 ] && trace SEVERE "failed chmod 770 $2" && exitOrLoop + fi + else + trace "Skipping copy of '$1' to '$2' -- these files already match." + fi +} + # exportInstallHomes # purpose: export MW_HOME, WL_HOME, ORACLE_HOME # with defaults as needed From 0dec0980ebbb5c4ce1a50e9d3f9879035eddea16 Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Thu, 25 Aug 2022 12:36:18 -0400 Subject: [PATCH 2/4] Fix script --- operator/src/main/resources/scripts/utils.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/src/main/resources/scripts/utils.sh b/operator/src/main/resources/scripts/utils.sh index a63dc976608..604fa3acabf 100755 --- a/operator/src/main/resources/scripts/utils.sh +++ b/operator/src/main/resources/scripts/utils.sh @@ -26,8 +26,8 @@ function copyIfChanged() { if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then trace "Copying '$1' to '$2'." tmp_file=$(mktemp -p $(dirname $1)) - cp $1 tmp_file - mv tmp_file $2 + cp $1 $tmp_file + mv $tmp_file $2 [ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop if [ -O "$2" ]; then chmod 770 $2 From 69018ec3b87c33ef36c98afc03c11a8d5fb11e3c Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Thu, 25 Aug 2022 12:36:55 -0400 Subject: [PATCH 3/4] Fix script --- operator/src/main/resources/scripts/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/src/main/resources/scripts/utils.sh b/operator/src/main/resources/scripts/utils.sh index 604fa3acabf..c2676d2094e 100755 --- a/operator/src/main/resources/scripts/utils.sh +++ b/operator/src/main/resources/scripts/utils.sh @@ -25,7 +25,7 @@ function copyIfChanged() { [ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1 if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then trace "Copying '$1' to '$2'." - tmp_file=$(mktemp -p $(dirname $1)) + tmp_file=$(mktemp -p $(dirname $2)) cp $1 $tmp_file mv $tmp_file $2 [ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop From ee3620bd4c7a87b2bc8a162feba83177b6d0eca8 Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Thu, 25 Aug 2022 16:06:02 -0400 Subject: [PATCH 4/4] Add explanatory comment --- operator/src/main/resources/scripts/utils.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/operator/src/main/resources/scripts/utils.sh b/operator/src/main/resources/scripts/utils.sh index c2676d2094e..3ce8810833f 100755 --- a/operator/src/main/resources/scripts/utils.sh +++ b/operator/src/main/resources/scripts/utils.sh @@ -25,6 +25,10 @@ function copyIfChanged() { [ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1 if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then trace "Copying '$1' to '$2'." + # Copy the source file to a temporary file in the same directory as the target and then + # move the temporary file to the target. This is done because the target file may be read by another + # process during the copy operation, such as can happen for situational configuration files stored in a + # domain home on a persistent volume. tmp_file=$(mktemp -p $(dirname $2)) cp $1 $tmp_file mv $tmp_file $2