github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/containers/ddev-webserver/ddev-webserver-base-scripts/healthcheck.sh (about)

     1  #!/bin/sh
     2  
     3  # This uses /bin/sh, so it doesn't initialize profile/bashrc/etc
     4  
     5  # ddev-webserver healthcheck
     6  
     7  set -e
     8  
     9  sleeptime=59
    10  
    11  # Make sure that phpstatus, mounted code, webserver and mailpit
    12  # are working.
    13  # Since docker doesn't provide a lazy period for startup,
    14  # we track health. If the last check showed healthy
    15  # as determined by existence of /tmp/healthy, then
    16  # sleep at startup. This requires the timeout to be set
    17  # higher than the sleeptime used here.
    18  if [ -f /tmp/healthy ]; then
    19      printf "container was previously healthy, so sleeping %s seconds before continuing healthcheck... " ${sleeptime}
    20      sleep ${sleeptime}
    21  fi
    22  
    23  # Shutdown the supervisor if one of the critical processes is in the FATAL state
    24  for service in php-fpm nginx apache2; do
    25    if supervisorctl status "${service}" 2>/dev/null | grep -q FATAL; then
    26      printf "%s:FATAL " "${service}"
    27      supervisorctl shutdown
    28    fi
    29  done
    30  
    31  phpstatus="false"
    32  htmlaccess="false"
    33  gunicornstatus="false"
    34  mailpit="false"
    35  
    36  if ls /var/www/html >/dev/null; then
    37      htmlaccess="true"
    38      printf "/var/www/html:OK "
    39  else
    40      printf "/var/www/html:FAILED "
    41  fi
    42  
    43  if curl --fail -s 127.0.0.1:8025 >/dev/null; then
    44      mailpit="true"
    45      printf "mailpit:OK "
    46  else
    47      printf "mailpit:FAILED "
    48  fi
    49  
    50  # If DDEV_WEBSERVER_TYPE is not set, use reasonable default
    51  DDEV_WEBSERVER_TYPE=${DDEV_WEBSERVER_TYPE:-nginx-fpm}
    52  
    53  if [ "${DDEV_WEBSERVER_TYPE#*-}" = "gunicorn" ]; then
    54    phpstatus="true"
    55    if pkill -0 gunicorn; then
    56      gunicornstatus="true"
    57      printf "gunicorn:OK "
    58    else
    59      printf "gunicorn:FAILED "
    60    fi
    61  
    62  fi
    63  
    64  if [ "${DDEV_WEBSERVER_TYPE#*-}" = "fpm" ]; then
    65    gunicornstatus="true"
    66    if curl --fail -s 127.0.0.1/phpstatus >/dev/null; then
    67      phpstatus="true"
    68      printf "phpstatus:OK "
    69    else
    70      printf "phpstatus:FAILED "
    71    fi
    72  fi
    73  
    74  if [ "${phpstatus}" = "true" ] && [ "${gunicornstatus}" = "true" ] && [ "${htmlaccess}" = "true" ] && [ "${mailpit}" = "true" ]; then
    75      touch /tmp/healthy
    76      exit 0
    77  fi
    78  rm -f /tmp/healthy
    79  
    80  exit 1