Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.
Closed
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
28 changes: 24 additions & 4 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,30 @@ else
echo "PJSe.json already exists at $PJSe_FILE"
fi

echo "Waiting for Postgres at ${POSTGRESQL_HOST:-postgres}:${POSTGRESQL_PORT:-5432}..."
until pg_isready -h "${POSTGRESQL_HOST:-postgres}" -p "${POSTGRESQL_PORT:-5432}" -U "${POSTGRESQL_USER:-postgres}" >/dev/null 2>&1; do
sleep 1
# Wait for PostgreSQL with timeout
POSTGRES_MAX_RETRIES="${POSTGRES_MAX_RETRIES:-60}"
POSTGRES_RETRY_DELAY="${POSTGRES_RETRY_DELAY:-1}"
POSTGRES_RETRY_COUNT=0

POSTGRES_TIMEOUT=$((POSTGRES_MAX_RETRIES * POSTGRES_RETRY_DELAY))
echo "Waiting for Postgres at ${POSTGRESQL_HOST:-postgres}:${POSTGRESQL_PORT:-5432}... (max ${POSTGRES_MAX_RETRIES} attempts, ${POSTGRES_TIMEOUT}s timeout)"
while ! pg_isready -h "${POSTGRESQL_HOST:-postgres}" -p "${POSTGRESQL_PORT:-5432}" -U "${POSTGRESQL_USER:-postgres}" >/dev/null 2>&1; do
POSTGRES_RETRY_COUNT=$((POSTGRES_RETRY_COUNT + 1))

if [ "$POSTGRES_RETRY_COUNT" -gt "$POSTGRES_MAX_RETRIES" ]; then
echo "ERROR: PostgreSQL did not become available after ${POSTGRES_MAX_RETRIES} attempts (${POSTGRES_TIMEOUT}s timeout)"
echo "Please check your PostgreSQL configuration and ensure the database is running"
exit 1
fi

sleep "$POSTGRES_RETRY_DELAY"
done

echo "Postgres is available. Starting app..."
if [ "$POSTGRES_RETRY_COUNT" -eq 0 ]; then
echo "Postgres is available. Starting app..."
elif [ "$POSTGRES_RETRY_COUNT" -eq 1 ]; then
echo "Postgres is available after 1 attempt. Starting app..."
else
echo "Postgres is available after ${POSTGRES_RETRY_COUNT} attempts. Starting app..."
fi
exec "$@"