Last active
March 28, 2024 20:41
-
-
Save valmayaki/900371ff18cd89bd55df358a468eae8f to your computer and use it in GitHub Desktop.
Wait for Connection ready
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!!