Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Oracle Database health check only after startup is finished #2882

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ ENV ORACLE_BASE=/u01/app/oracle \
CONFIG_RSP="xe.rsp" \
RUN_FILE="runOracle.sh" \
PWD_FILE="setPassword.sh" \
CHECK_DB_FILE="checkDBStatus.sh"
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started"

# Use second ENV so that variable get substituted
ENV PATH=$ORACLE_HOME/bin:$PATH
Expand Down Expand Up @@ -89,4 +90,4 @@ RUN yum -y install unzip libaio bc initscripts net-tools openssl compat-libstdc+
HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

POSITIVE_RETURN="OPEN"
# shellcheck disable=SC2034
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"

# Check Oracle DB status and store it in status
Expand Down
12 changes: 9 additions & 3 deletions OracleDatabase/SingleInstance/dockerfiles/11.2.0.2/runOracle.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ function runUserScripts {

for f in $SCRIPTS_ROOT/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sh)
echo "$0: running $f"
# shellcheck disable=SC1090
. "$f"
;;
*.sql) echo "$0: running $f"; echo "exit" | su -p oracle -c "$ORACLE_HOME/bin/sqlplus / as sysdba @$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
Expand Down Expand Up @@ -175,7 +179,7 @@ fi;
/etc/init.d/oracle-xe start | grep -qc "Oracle Database 11g Express Edition is not configured"
if [ "$?" == "0" ]; then
# Check whether container has enough memory
if [ `df -Pk /dev/shm | tail -n 1 | awk '{print $2}'` -lt 1048576 ]; then
if [ "`df -Pk /dev/shm | tail -n 1 | awk '{print $2}'`" -lt 1048576 ]; then
echo "Error: The container doesn't have enough memory allocated."
echo "A database XE container needs at least 1 GB of shared memory (/dev/shm)."
echo "You currently only have $((`df -Pk /dev/shm | tail -n 1 | awk '{print $2}'`/1024)) MB allocated to the container."
Expand All @@ -190,7 +194,7 @@ if [ "$?" == "0" ]; then
fi;

# Check whether database is up and running
$ORACLE_BASE/$CHECK_DB_FILE
IGNORE_DB_STARTED_MARKER=true $ORACLE_BASE/$CHECK_DB_FILE
if [ $? -eq 0 ]; then
echo "#########################"
echo "DATABASE IS READY TO USE!"
Expand All @@ -199,6 +203,8 @@ if [ $? -eq 0 ]; then
# Execute custom provided startup scripts
runUserScripts $ORACLE_BASE/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ENV ORACLE_BASE=/opt/oracle \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
USER_SCRIPTS_FILE="runUserScripts.sh" \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh"

Expand Down Expand Up @@ -119,4 +120,4 @@ HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ENV ORACLE_BASE=/opt/oracle \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
USER_SCRIPTS_FILE="runUserScripts.sh" \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh"

Expand Down Expand Up @@ -119,4 +120,4 @@ HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

# shellcheck disable=SC2034
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
OPEN_MODE="READ WRITE"
# shellcheck disable=SC2034
ORAENV_ASK=NO
# shellcheck disable=SC1090
source oraenv

# Check Oracle at least one PDB has open_mode "READ WRITE" and store it in status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ else
fi;

# Check whether database is up and running
$ORACLE_BASE/$CHECK_DB_FILE
IGNORE_DB_STARTED_MARKER=true $ORACLE_BASE/$CHECK_DB_FILE
if [ $? -eq 0 ]; then
echo "#########################"
echo "DATABASE IS READY TO USE!"
Expand All @@ -187,6 +187,8 @@ if [ $? -eq 0 ]; then
# Execute custom provided startup scripts
$ORACLE_BASE/$USER_SCRIPTS_FILE $ORACLE_BASE/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ENV ORACLE_BASE=/opt/oracle \
RUN_FILE="runOracle.sh" \
START_FILE="startDB.sh" \
CREATE_DB_FILE="createDB.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
Expand Down Expand Up @@ -116,4 +117,4 @@ HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

# shellcheck disable=SC2034
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
OPEN_MODE="READ WRITE"
# shellcheck disable=SC2034
ORAENV_ASK=NO
# shellcheck disable=SC1090
source oraenv

# Check Oracle at least one PDB has open_mode "READ WRITE" and store it in status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ else
fi;

# Check whether database is up and running
$ORACLE_BASE/$CHECK_DB_FILE
IGNORE_DB_STARTED_MARKER=true $ORACLE_BASE/$CHECK_DB_FILE
if [ $? -eq 0 ]; then
echo "#########################"
echo "DATABASE IS READY TO USE!"
Expand All @@ -187,6 +187,8 @@ if [ $? -eq 0 ]; then
# Execute custom provided startup scripts
$ORACLE_BASE/$USER_SCRIPTS_FILE $ORACLE_BASE/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ENV ORACLE_BASE=/opt/oracle \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
USER_SCRIPTS_FILE="runUserScripts.sh" \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh"

Expand Down Expand Up @@ -116,4 +117,4 @@ HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

# shellcheck disable=SC2034
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
OPEN_MODE="READ WRITE"
# shellcheck disable=SC2034
ORAENV_ASK=NO
# shellcheck disable=SC1090
source oraenv

# Check Oracle at least one PDB has open_mode "READ WRITE" and store it in status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ else
fi;

# Check whether database is up and running
$ORACLE_BASE/$CHECK_DB_FILE
IGNORE_DB_STARTED_MARKER=true $ORACLE_BASE/$CHECK_DB_FILE
if [ $? -eq 0 ]; then
echo "#########################"
echo "DATABASE IS READY TO USE!"
Expand All @@ -187,6 +187,8 @@ if [ $? -eq 0 ]; then
# Execute custom provided startup scripts
$ORACLE_BASE/$USER_SCRIPTS_FILE $ORACLE_BASE/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ RUN chmod ug+x $INSTALL_DIR/*.sh && \
HEALTHCHECK --interval=1m --start-period=5m \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

# shellcheck disable=SC2034
ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`"
OPEN_MODE="READ WRITE"
# shellcheck disable=SC2034
ORAENV_ASK=NO
# shellcheck disable=SC1090
source oraenv

[ -f "$ORACLE_BASE/oradata/dbconfig/$ORACLE_SID/oratab" ] || exit 1;
Expand Down
10 changes: 8 additions & 2 deletions OracleDatabase/SingleInstance/dockerfiles/18.4.0/runOracle.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ function runUserScripts {

for f in $SCRIPTS_ROOT/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sh)
echo "$0: running $f"
# shellcheck disable=SC1090
. "$f"
;;
*.sql) echo "$0: running $f"; echo "exit" | su -p oracle -c "$ORACLE_HOME/bin/sqlplus / as sysdba @$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
Expand Down Expand Up @@ -201,7 +205,7 @@ if [ "$?" == "0" ]; then
fi;

# Check whether database is up and running
$ORACLE_BASE/$CHECK_DB_FILE
IGNORE_DB_STARTED_MARKER=true $ORACLE_BASE/$CHECK_DB_FILE
if [ $? -eq 0 ]; then
echo "#########################"
echo "DATABASE IS READY TO USE!"
Expand All @@ -210,6 +214,8 @@ if [ $? -eq 0 ]; then
# Execute custom provided startup scripts
runUserScripts $ORACLE_BASE/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ENV ORACLE_BASE=/opt/oracle \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
USER_SCRIPTS_FILE="runUserScripts.sh" \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh" \
RELINK_BINARY_FILE="relinkOracleBinary.sh" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,26 @@ EOF
################ MAIN #######################
#############################################

if [ "$IGNORE_DB_STARTED_MARKER" != true ] && [ ! -f "$DB_STARTED_MARKER_FILE" ]; then
echo "Database was not started yet." >&2
exit 1
fi

# Setting up ORACLE_PWD if podman secret is passed on
if [ -e '/run/secrets/oracle_pwd' ]; then
export ORACLE_PWD="$(cat '/run/secrets/oracle_pwd')"
ORACLE_PWD="$(cat '/run/secrets/oracle_pwd')"
export ORACLE_PWD
fi

if [ "$DG_OBSERVER_ONLY" = "true" ]; then
checkObserver
else
# shellcheck disable=SC2034
ORACLE_SID="$(grep "$ORACLE_HOME" /etc/oratab | cut -d: -f1)"
DB_ROLE=""
# shellcheck disable=SC2034
ORAENV_ASK=NO
# shellcheck disable=SC1090
source oraenv
checkDatabaseRole
checkPDBOpen
Expand Down
10 changes: 7 additions & 3 deletions OracleDatabase/SingleInstance/dockerfiles/19.3.0/runOracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function moveFiles {
mv "$ORACLE_HOME"/network/admin/sqlnet.ora "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
mv "$ORACLE_HOME"/network/admin/listener.ora "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
mv "$ORACLE_HOME"/network/admin/tnsnames.ora "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
mv "$ORACLE_HOME"/install/.docker_* "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
if [ -n "$(shopt -s nullglob; echo "$ORACLE_HOME"/install/.docker_*)" ]; then
mv "$ORACLE_HOME"/install/.docker_* "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
fi;

# oracle user does not have permissions in /etc, hence cp and not mv
cp /etc/oratab "$ORACLE_BASE"/oradata/dbconfig/"$ORACLE_SID"/
Expand Down Expand Up @@ -272,7 +274,7 @@ else
"$ORACLE_BASE"/"$CREATE_DB_FILE" "$ORACLE_SID" "$ORACLE_PDB" "$ORACLE_PWD" || exit 1;

# Check whether database is successfully created
if "$ORACLE_BASE"/"$CHECK_DB_FILE"; then
if IGNORE_DB_STARTED_MARKER=true "$ORACLE_BASE"/"$CHECK_DB_FILE"; then
# Create a checkpoint file if database is successfully created
# Populate the checkpoint file with the current date to avoid timing issue when using NFS persistence in multi-replica mode
date -Iseconds > "$ORACLE_BASE"/oradata/."${ORACLE_SID}""${CHECKPOINT_FILE_EXTN}"
Expand All @@ -295,7 +297,7 @@ else
fi;

# Check whether database is up and running
"$ORACLE_BASE"/"$CHECK_DB_FILE"
IGNORE_DB_STARTED_MARKER=true "$ORACLE_BASE"/"$CHECK_DB_FILE"
status=$?

if [ $status -eq 0 ]; then
Expand All @@ -308,6 +310,8 @@ if [ $status -eq 0 ]; then
# Execute custom provided startup scripts
"$ORACLE_BASE"/"$USER_SCRIPTS_FILE" "$ORACLE_BASE"/scripts/startup

# Create marker file for the health check
touch "$DB_STARTED_MARKER_FILE"
else
echo "#####################################"
echo "########### E R R O R ###############"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ENV ORACLE_BASE=/opt/oracle \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
USER_SCRIPTS_FILE="runUserScripts.sh" \
INSTALL_DB_BINARIES_FILE="installDBBinaries.sh" \
RELINK_BINARY_FILE="relinkOracleBinary.sh" \
Expand Down Expand Up @@ -139,4 +140,4 @@ HEALTHCHECK --interval=1m --start-period=5m --timeout=30s \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

# Define default command to start Oracle Database.
CMD exec $ORACLE_BASE/$RUN_FILE
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ENV ORACLE_BASE=/opt/oracle \
CONF_FILE="oracle-xe-21c.conf" \
CHECK_SPACE_FILE="checkSpace.sh" \
CHECK_DB_FILE="checkDBStatus.sh" \
DB_STARTED_MARKER_FILE="/dev/shm/.db_started" \
SETUP_LINUX_FILE="setupLinuxEnv.sh" \
CONFIG_TCPS_FILE="configTcps.sh" \
INSTALL_DIR="$HOME/install" \
Expand Down Expand Up @@ -90,4 +91,4 @@ WORKDIR /home/oracle
HEALTHCHECK --interval=1m --start-period=5m --timeout=30s \
CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1

CMD [ "/bin/bash", "-c", "$ORACLE_BASE/$RUN_FILE" ]
CMD [ "/bin/bash", "-c", "exec $ORACLE_BASE/$RUN_FILE" ]
Loading