github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/containers/ddev-router/healthcheck.sh (about) 1 #!/bin/bash 2 set -eu 3 set -o pipefail 4 5 sleeptime=59 6 7 # Since docker doesn't provide a lazy period for startup, 8 # we track health. If the last check showed healthy 9 # as determined by existence of /tmp/healthy, then 10 # sleep at startup. This requires the timeout to be set 11 # higher than the sleeptime used here. 12 if [ -f /tmp/healthy ]; then 13 printf "container was previously healthy, so sleeping ${sleeptime} seconds before continuing healthcheck... " 14 sleep ${sleeptime} 15 fi 16 17 config=false 18 connect=false 19 configgenerated=false 20 21 if nginx -t 2>/dev/null; then 22 config=true 23 printf "nginx config valid:OK " 24 else 25 printf "nginx configuration invalid: $(nginx -t 2>&1)" 26 exit 2 27 fi 28 29 if [ -f /etc/nginx/conf.d/ddev.conf ]; then 30 configgenerated=true 31 printf "ddev nginx config:generated " 32 else 33 printf "ddev nginx config not yet generated " 34 exit 3 35 fi 36 37 # Check our healthcheck endpoint 38 if curl -s --fail --connect-timeout 2 --retry 2 http://127.0.0.1/healthcheck; then 39 connect=true 40 printf "nginx healthcheck endpoint:OK " 41 else 42 printf "healthcheck endpoint not responding " 43 exit 4 44 fi 45 46 if [ ${config} = true -a ${connect} = true -a ${configgenerated} = true ]; then 47 printf "ddev-router is healthy with %d upstreams" $(grep "upstream.*-" /etc/nginx/conf.d/ddev.conf | wc -l) 48 touch /tmp/healthy 49 exit 0 50 fi 51 52 rm -f /tmp/healthy 53 exit 1