github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/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    touch /tmp/healthy
    29    exit 0
    30  fi
    31  
    32  # If we can now access the server, we're healthy and ready
    33  if  mysql --host=127.0.0.1 -udb -pdb --database=db -e "SHOW DATABASES LIKE 'db';" >/dev/null;  then
    34      printf "healthy"
    35      touch /tmp/healthy
    36      exit 0
    37  fi
    38  
    39  rm -f /tmp/healthy
    40  exit 1
    41