Skip to content

Commit

Permalink
start: Avoid probing server version with WEBLATE_DATABASES=False
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Sep 27, 2023
1 parent 643aa8b commit 141162d
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,39 @@ fi

# Wait for database to get available
TIMEOUT=0
until psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -d "$POSTGRES_DATABASE" -U "$POSTGRES_USER" -c 'SELECT 1' > /dev/null ; do
>&2 echo "Postgres at ${POSTGRES_HOST:-db} is unavailable - retrying $((30 - TIMEOUT))"
until run_weblate shell -c 'from weblate.auth.models import User; User.objects.raw("SELECT 1")' > /dev/null ; do
>&2 echo "Database server at ${POSTGRES_HOST:-db} is unavailable - retrying $((30 - TIMEOUT))"
TIMEOUT=$((TIMEOUT + 1))
if [ $TIMEOUT -gt 30 ] ; then
psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -d "$POSTGRES_DATABASE" -U "$POSTGRES_USER" -c 'SELECT 1'
run_weblate shell -c 'from weblate.auth.models import User; User.objects.exists()'
fail_dep PosgreSQL
fi
sleep 1
done

# Fetch server version
PGVERSION=$(psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -d "$POSTGRES_DATABASE" -U "$POSTGRES_USER" -t -A -c 'SHOW server_version_num;')
VERSION_CHECK=1
case $WEBLATE_DATABASES in
0|[fF][aA][lL][sS][eE]|[nN][oO])
VERSION_CHECK=0
;;
esac

unset PGPASSWORD
if [ $VERSION_CHECK -eq 1 ] ; then
# Fetch server version
PGVERSION=$(psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -d "$POSTGRES_DATABASE" -U "$POSTGRES_USER" -t -A -c 'SHOW server_version_num;')

>&2 echo "Postgres $PGVERSION is up"
unset PGPASSWORD

# Check if supported PostgreSQL version is used
if [ "$PGVERSION" -lt 120000 ] ; then
>&2 echo "PostgreSQL 12 or newer is required to run Weblate"
>&2 echo "See https://docs.weblate.org/en/latest/admin/install/docker.html#upgrading-postgresql-container"
exit 1
>&2 echo "Postgres $PGVERSION is up"

# Check if supported PostgreSQL version is used
if [ "$PGVERSION" -lt 120000 ] ; then
>&2 echo "PostgreSQL 12 or newer is required to run Weblate"
>&2 echo "See https://docs.weblate.org/en/latest/admin/install/docker.html#upgrading-postgresql-container"
exit 1
fi
else
>&2 echo "Database is up"
fi

# Migrate database to current version and collect static files
Expand Down

0 comments on commit 141162d

Please sign in to comment.