Skip to content

Commit

Permalink
Copy situational configuration using a temporary file and mv to impro…
Browse files Browse the repository at this point in the history
…ve concurrency (#3359)

* Use mv while updating situational configuration files to improve concurrency
  • Loading branch information
rjeberhard authored Aug 25, 2022
1 parent 552654f commit f1622fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
6 changes: 3 additions & 3 deletions operator/src/main/resources/scripts/livenessProbe.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 1 addition & 20 deletions operator/src/main/resources/scripts/startServer.sh
Original file line number Diff line number Diff line change
@@ -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.

#
Expand Down Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion operator/src/main/resources/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +17,31 @@ 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'."
# 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
[ $? -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
Expand Down

0 comments on commit f1622fc

Please sign in to comment.