github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/containers/ddev-dbserver/files/healthcheck.sh (about) 1 #!/bin/bash 2 3 ## mysql health check for docker 4 5 set -eo pipefail 6 sleeptime=59 7 8 # Since docker doesn't provide a lazy period for startup, 9 # we track health. If the last check showed healthy 10 # as determined by existence of /tmp/healthy, then 11 # sleep at startup. This requires the timeout to be set 12 # higher than the sleeptime used here. 13 if [ -f /tmp/healthy ]; then 14 printf "container was previously healthy, so sleeping ${sleeptime} seconds before continuing healthcheck... " 15 sleep ${sleeptime} 16 fi 17 18 # If /tmp/initializing, it means we're loading the default starter database 19 if [ -f /tmp/initializing ]; then 20 printf "initializing" 21 exit 1 22 fi 23 24 # If mariabackup or xtrabackup is running (and not initializing) 25 # It means snapshot restore is in progress 26 if killall -0 mariabackup 2>/dev/null || killall -0 xtrabackup 2>/dev/null ; then 27 printf "currently restoring snapshot" 28 exit 2 29 fi 30 31 # If we can now access the server, we're healthy and ready 32 if mysql --host=127.0.0.1 -udb -pdb --database=db -e "SHOW DATABASES LIKE 'db';" >/dev/null; then 33 printf "healthy" 34 touch /tmp/healthy 35 exit 0 36 fi 37 38 rm -f /tmp/healthy 39 exit 1 40