Skip to content

Instantly share code, notes, and snippets.

@valmayaki
Last active March 28, 2024 20:41
Show Gist options
  • Save valmayaki/900371ff18cd89bd55df358a468eae8f to your computer and use it in GitHub Desktop.
Save valmayaki/900371ff18cd89bd55df358a468eae8f to your computer and use it in GitHub Desktop.
Wait for Connection ready
#!/bin/sh
until docker-compose exec mysql mysql -h 127.0.0.1 -u $DB_USERNAME -p$DB_PASSWORD -D $DB_DATABASE --silent -e "show databases;"
do
echo "Waiting for database connection..."
sleep 5
done
#!/bin/sh
failcounter=0
timeout_in_sec=120
until docker exec mysql mysqladmin --user=root --password=${MYSQL_ROOT_PASSWORD} --host "127.0.0.1" ping --silent &> /dev/null ; do
let "failcounter += 1"
echo "Waiting for database connection..."
if [[ $failcounter -gt timeout_in_sec ]]; then
echo "Timeout ($timeout_in_sec seconds) reached; failed to connect to database"
exit 1
fi
sleep 2
done
#!/bin/sh
## reference https://starkandwayne.com/blog/how-to-know-when-your-postgres-service-is-ready/
pg_uri="postgres://postgres:postgres@postgrest-host:5432/shield"
# make sure pg is ready to accept connections
until pg_isready -h postgres-host -p 5432 -U postgres
do
echo "Waiting for postgres at: $pg_uri"
sleep 2;
done
# Now able to connect to postgres
#!/bin/sh
#waiting for postgres
until psql --host=$KONG_PG_HOST --username=$POLLING_USER $POLLING_DATABASE -w &>/dev/null
do
echo "Waiting for PostgreSQL..."
sleep 1
done
#!/bin/sh
failcounter=0
timeout_in_sec=120
until docker exec postgres pg_isready --username=root --host="127.0.0.1" --quiet &> /dev/null ; do
let "failcounter += 1"
echo "Waiting for database connection..."
if [[ $failcounter -gt timeout_in_sec ]]; then
echo "Timeout ($timeout_in_sec seconds) reached; failed to connect to database"
exit 1
fi
sleep 2
done
@f-asa
Copy link

f-asa commented Mar 28, 2024

thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment