Skip to content

Commit

Permalink
feat(db-checker): Extension of "db reachable"
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jan 26, 2025
1 parent b9fa253 commit 3f36a4e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions docker/entrypoint-celery-beat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

umask 0002
Expand Down
3 changes: 3 additions & 0 deletions docker/entrypoint-uwsgi-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

wait_for_database_to_be_reachable
echo

cd /app || exit

Expand Down
4 changes: 4 additions & 0 deletions docker/entrypoint-uwsgi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e # needed to handle "exit" correctly

. /secret-file-loader.sh
. /reach_database.sh

# Allow for bind-mount multiple settings.py overrides
FILES=$(ls /app/docker/extra_settings/* 2>/dev/null || true)
Expand All @@ -17,6 +18,9 @@ if [ "$NUM_FILES" -gt 0 ]; then
rm -f /app/dojo/settings/README.md
fi

wait_for_database_to_be_reachable
echo

umask 0002

# do the check with Django stack
Expand Down
23 changes: 17 additions & 6 deletions docker/reach_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ wait_for_database_to_be_reachable() {
DD_DATABASE_READINESS_TIMEOUT=${DD_DATABASE_READINESS_TIMEOUT:-30}
until echo "select 1;" | python3 manage.py dbshell > /dev/null
do
echo -n "."
failure_count=$((failure_count + 1))
sleep 1
if [ $DD_DATABASE_READINESS_TIMEOUT = $failure_count ]; then
exit 1
fi
echo -n "."
failure_count=$((failure_count + 1))
sleep 1
if [ $DD_DATABASE_READINESS_TIMEOUT = $failure_count ]; then
exit 1
fi
done
cat <<EOD | python manage.py shell
from django.db import connections
connections['default'].cursor()
EOD
DB_TEST=$?
if [[ $DB_TEST -ne 0 ]]; then
echo "Simple database test failed with $DB_TEST"
else
echo "Simple database test was successful"
fi
return $DB_TEST
}

0 comments on commit 3f36a4e

Please sign in to comment.