github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/containers/ddev-webserver/ddev-webserver-prod-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 both phpstatus, mounted code NOT mailhog
    12  # (mailhog is excluded on hardened/prod)
    13  # are working.
    14  # Since docker doesn't provide a lazy period for startup,
    15  # we track health. If the last check showed healthy
    16  # as determined by existence of /tmp/healthy, then
    17  # sleep at startup. This requires the timeout to be set
    18  # higher than the sleeptime used here.
    19  if [ -f /tmp/healthy ]; then
    20      printf "container was previously healthy, so sleeping ${sleeptime} seconds before continuing healthcheck...  "
    21      sleep ${sleeptime}
    22  fi
    23  
    24  phpstatus="false"
    25  htmlaccess="false"
    26  if curl --fail -s 127.0.0.1/phpstatus >/dev/null ; then
    27      phpstatus="true"
    28      printf "phpstatus: OK "
    29  else
    30      printf "phpstatus: FAILED "
    31  fi
    32  
    33  if ls /var/www/html >/dev/null; then
    34      htmlaccess="true"
    35      printf "/var/www/html: OK "
    36  else
    37      printf "/var/www/html: FAILED"
    38  fi
    39  
    40  if [ "${phpstatus}" = "true" ] && [ "${htmlaccess}" = "true" ]; then
    41      touch /tmp/healthy
    42      exit 0
    43  fi
    44  rm -f /tmp/healthy
    45  exit 1
    46  
    47