Skip to content

Instantly share code, notes, and snippets.

@rafiramadhana
Created March 12, 2023 03:46
Show Gist options
  • Save rafiramadhana/f9956246ac6e53ebd20a137c4c0f6e8c to your computer and use it in GitHub Desktop.
Save rafiramadhana/f9956246ac6e53ebd20a137c4c0f6e8c to your computer and use it in GitHub Desktop.
Wait until MySQL not rungkat
#!/bin/sh
# Docker-compose check if mysql connection is ready
# https://stackoverflow.com/a/51641089
maxcounter=30
counter=1
while ! mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"0.0.0.0" -P"3306" -e "SHOW DATABASES;" > /dev/null 2>&1; do
sleep 1
counter=`expr $counter + 1`
if [ $counter -gt $maxcounter ]; then
>&2 echo "Too long waiting for MySQL; failing."
exit 1
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment