2019-08-23 08:47:19 -07:00
|
|
|
#!/bin/sh
|
2019-11-26 02:44:14 -08:00
|
|
|
|
|
|
|
maxcounter=${MAX_DB_CONN_ATTEMPTS:-60}
|
|
|
|
|
|
|
|
if [ "$maxcounter" -le 0 ]; then
|
|
|
|
echo "Skipping wait-for-it.sh..."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$BACKEND" ]; then
|
|
|
|
echo "ERROR: variable 'BACKEND' must be set. Exiting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# wait until the database is really available
|
|
|
|
echo "Trying to connect to $BACKEND (timeout=${maxcounter}s)"
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
ready () {
|
|
|
|
|
|
|
|
if [ "$BACKEND" = "mysql" ]; then
|
|
|
|
mysql \
|
|
|
|
--host="$DB_HOST" \
|
|
|
|
--protocol TCP \
|
|
|
|
-u"$DB_USER" \
|
|
|
|
-p"$DB_PASSWORD" \
|
|
|
|
-e "show databases;" > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
PGPASSWORD="$DB_PASSWORD" psql \
|
|
|
|
-h "$DB_HOST" \
|
|
|
|
-U "$DB_USER" \
|
|
|
|
-c "select * from pg_database" > /dev/null 2>&1
|
|
|
|
fi
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2019-08-23 08:47:19 -07:00
|
|
|
|
|
|
|
counter=1
|
2019-11-26 02:44:14 -08:00
|
|
|
while ! ready; do
|
2019-08-23 08:47:19 -07:00
|
|
|
counter=`expr $counter + 1`
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2019-08-23 08:47:19 -07:00
|
|
|
if [ $counter -gt $maxcounter ]; then
|
2019-11-26 02:44:14 -08:00
|
|
|
>&2 echo "ERROR: Could not connect to $BACKEND after $MAX_DB_CONN_ATTEMPTS seconds; Exiting."
|
2019-08-23 08:47:19 -07:00
|
|
|
exit 1
|
|
|
|
fi;
|
2019-11-26 02:44:14 -08:00
|
|
|
sleep 1
|
2019-08-23 08:47:19 -07:00
|
|
|
done
|
2019-11-26 02:44:14 -08:00
|
|
|
|
2019-08-23 08:47:19 -07:00
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
echo "-=------------------------------------------------------"
|
2019-11-26 02:44:14 -08:00
|
|
|
echo "Connected to $BACKEND!"
|
2019-08-23 08:47:19 -07:00
|
|
|
echo "-=------------------------------------------------------"
|
|
|
|
echo "-=------------------------------------------------------"
|