mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 04:49:37 +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:
parent
3f6aa67b3f
commit
9eaaadc0f2
2 changed files with 25 additions and 2 deletions
|
@ -1,10 +1,32 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Function to check PostgreSQL availability
|
# Function to check PostgreSQL availability
|
||||||
check_postgres() {
|
# Helper to get the first non-empty environment variable
|
||||||
PGPASSWORD=$PGPASSWORD psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -c '\q' >/dev/null 2>&1
|
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
|
# Wait for PostgreSQL to become available
|
||||||
until check_postgres; do
|
until check_postgres; do
|
||||||
>&2 echo "PostgreSQL is unavailable - sleeping"
|
>&2 echo "PostgreSQL is unavailable - sleeping"
|
||||||
|
|
|
@ -484,6 +484,7 @@ wait_for_services() {
|
||||||
|
|
||||||
local max_attempts=30
|
local max_attempts=30
|
||||||
local attempt=1
|
local attempt=1
|
||||||
|
|
||||||
while [ $attempt -le $max_attempts ]; do
|
while [ $attempt -le $max_attempts ]; do
|
||||||
if curl -s -o /dev/null -w "%{http_code}" "$FRONTEND_ORIGIN" | grep -q "200\|404\|302"; then
|
if curl -s -o /dev/null -w "%{http_code}" "$FRONTEND_ORIGIN" | grep -q "200\|404\|302"; then
|
||||||
log_success "Frontend is responding"
|
log_success "Frontend is responding"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue