Last active
October 27, 2021 14:44
-
-
Save jesugmz/f63a1e9bd338fad33aa0cc62b815d4e3 to your computer and use it in GitHub Desktop.
MySQL healt check for Docker containers, or whatever
This file contains 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/bash | |
# Maximum retries we want to iterate | |
MAX_RETRIES=10 | |
retries=0 | |
echo -n "Waiting MySQL to be ready" | |
# mysqladmin ping will produce false positives when is ready but can not yet accept. | |
# With this solution, we ensure the output is what we expect for any case. | |
until [[ "$o" == "mysqld is alive" ]]; do | |
# Safeguard to avoid infinite loops | |
((retries=retries+1)) | |
if [ "$retries" -gt $MAX_RETRIES ]; then | |
exit 1 | |
fi | |
echo -n "." | |
sleep 1 | |
o=$(docker-compose exec -T nrst-db sh -c 'mysqladmin ping --no-beep 2> /dev/null') | |
done | |
# give some extra time to finish warming up in order to avoid random connection refusing | |
echo -n "hot standby." | |
sleep 2 | |
echo -n ".all systems go" | |
echo -ne "\n" | |
exit 0 |
This file contains 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
bash -c 'docker/mysql/healthcheck.sh; if [[ "$?" -eq 1 ]]; then echo "Was not possible to establish connection with MySQL"; exit 1; fi' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another way could be fetch Docker logs until a target log is reached out.