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: Avoid probing server version with WEBLATE_DATABASES=False #1980

Merged
merged 1 commit into from
Sep 27, 2023
Merged
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
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
Loading