1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-18 20:39:36 +02:00

Enhance entrypoint script with a helper function for environment variable retrieval; improve PostgreSQL connection logic. Update installer script to add spacing for readability in service wait function.

This commit is contained in:
Sean Morley 2025-05-26 17:36:22 -04:00
parent 3f6aa67b3f
commit 9eaaadc0f2
2 changed files with 25 additions and 2 deletions

View file

@ -1,10 +1,32 @@
#!/bin/bash
# Function to check PostgreSQL availability
check_postgres() {
PGPASSWORD=$PGPASSWORD psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -c '\q' >/dev/null 2>&1
# Helper to get the first non-empty environment variable
get_env() {
for var in "$@"; do
value="${!var}"
if [ -n "$value" ]; then
echo "$value"
return
fi
done
}
check_postgres() {
local db_host
local db_user
local db_name
local db_pass
db_host=$(get_env PGHOST)
db_user=$(get_env PGUSER POSTGRES_USER)
db_name=$(get_env PGDATABASE POSTGRES_DB)
db_pass=$(get_env PGPASSWORD POSTGRES_PASSWORD)
PGPASSWORD="$db_pass" psql -h "$db_host" -U "$db_user" -d "$db_name" -c '\q' >/dev/null 2>&1
}
# Wait for PostgreSQL to become available
until check_postgres; do
>&2 echo "PostgreSQL is unavailable - sleeping"

View file

@ -484,6 +484,7 @@ wait_for_services() {
local max_attempts=30
local attempt=1
while [ $attempt -le $max_attempts ]; do
if curl -s -o /dev/null -w "%{http_code}" "$FRONTEND_ORIGIN" | grep -q "200\|404\|302"; then
log_success "Frontend is responding"