You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
835 B

#!/bin/sh
timeout=120
start="$(date +%s)"
while true; do
if err=$(echo "SELECT 1;" | psql 2>&1 >/dev/null); then
break
fi
now=$(date +%s)
if ! [ "$err" = "psql: FATAL: the database system is starting up" ]; then
echo "postgres connection error:" \
"Could not connect to '$PGHOST'. (will retry)"
if [ "$err" ]; then
echo " Error:" >&2
printf "%s\n" "$err" | sed -r "s/^/ ! /g" >&2
fi
else
echo "Got 'database system is starting up' error... waiting before launching npm start" >&2
fi
elapsed=$((now - start))
if [ "$elapsed" -gt "$timeout" ]; then
echo "postgre connection error:"\
"Could not connect to db on '$PGHOST'" \
"container's IP."
exit 1
fi
sleep 0.5
done
exec npm start