Skip to content

Commit

Permalink
build: update hardened/prod healthcheck.sh, for ddev#6033
Browse files Browse the repository at this point in the history
  • Loading branch information
stasadev committed Apr 24, 2024
1 parent d358586 commit ec9b76b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/bin/sh

# This uses /bin/sh so it doesn't initialize profile/bashrc/etc
# This uses /bin/sh, so it doesn't initialize profile/bashrc/etc

# ddev-webserver healthcheck

set -e

sleeptime=59

# Make sure that mounted code, and mailpit
# Make sure that phpstatus, mounted code, webserver and mailpit
# are working.
# Since docker doesn't provide a lazy period for startup,
# we track health. If the last check showed healthy
# as determined by existence of /tmp/healthy, then
# sleep at startup. This requires the timeout to be set
# higher than the sleeptime used here.
if [ -f /tmp/healthy ]; then
printf "container was previously healthy, so sleeping ${sleeptime} seconds before continuing healthcheck... "
printf "container was previously healthy, so sleeping %s seconds before continuing healthcheck... " ${sleeptime}
sleep ${sleeptime}
fi

Expand Down Expand Up @@ -61,17 +61,17 @@ if [ "${DDEV_WEBSERVER_TYPE#*-}" = "gunicorn" ]; then

fi

if [ "${DDEV_WEBSERVER_TYPE#*-}" = "fpm" ]; then
if [ "${DDEV_WEBSERVER_TYPE#*-}" = "fpm" ]; then
gunicornstatus="true"
if curl --fail -s 127.0.0.1/phpstatus >/dev/null ; then
if curl --fail -s 127.0.0.1/phpstatus >/dev/null; then
phpstatus="true"
printf "phpstatus:OK "
else
printf "phpstatus:FAILED "
fi
fi

if [ "${phpstatus}" = "true" ] && [ "${gunicornstatus}" = "true" ] && [ "${htmlaccess}" = "true" ] && [ "${mailpit}" = "true" ] ; then
if [ "${phpstatus}" = "true" ] && [ "${gunicornstatus}" = "true" ] && [ "${htmlaccess}" = "true" ] && [ "${mailpit}" = "true" ]; then
touch /tmp/healthy
exit 0
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/sh

# This uses /bin/sh so it doesn't initialize profile/bashrc/etc
# This uses /bin/sh, so it doesn't initialize profile/bashrc/etc

# ddev-webserver healthcheck

set -e

sleeptime=59

# Make sure that both phpstatus, mounted code NOT mailpit
# Make sure that phpstatus, mounted code, webserver, NOT mailpit
# (mailpit is excluded on hardened/prod)
# are working.
# Since docker doesn't provide a lazy period for startup,
Expand All @@ -17,10 +17,18 @@ sleeptime=59
# sleep at startup. This requires the timeout to be set
# higher than the sleeptime used here.
if [ -f /tmp/healthy ]; then
printf "container was previously healthy, so sleeping ${sleeptime} seconds before continuing healthcheck... "
printf "container was previously healthy, so sleeping %s seconds before continuing healthcheck... " ${sleeptime}
sleep ${sleeptime}
fi

# Shutdown the supervisor if one of the critical processes is in the FATAL state
for service in php-fpm nginx apache2; do
if supervisorctl status "${service}" 2>/dev/null | grep -q FATAL; then
printf "%s:FATAL " "${service}"
supervisorctl shutdown
fi
done

phpstatus="false"
htmlaccess="false"
gunicornstatus="false"
Expand All @@ -29,7 +37,7 @@ if ls /var/www/html >/dev/null; then
htmlaccess="true"
printf "/var/www/html:OK "
else
printf "/var/www/html:FAILED"
printf "/var/www/html:FAILED "
fi

# If DDEV_WEBSERVER_TYPE is not set, use reasonable default
Expand All @@ -39,16 +47,16 @@ if [ "${DDEV_WEBSERVER_TYPE#*-}" = "gunicorn" ]; then
phpstatus="true"
if pkill -0 gunicorn; then
gunicornstatus="true"
printf "gunicorn:OK"
printf "gunicorn:OK "
else
printf "gunicorn:FAILED "
fi

fi

if [ "${DDEV_WEBSERVER_TYPE#*-}" = "fpm" ]; then
if [ "${DDEV_WEBSERVER_TYPE#*-}" = "fpm" ]; then
gunicornstatus="true"
if curl --fail -s 127.0.0.1/phpstatus >/dev/null ; then
if curl --fail -s 127.0.0.1/phpstatus >/dev/null; then
phpstatus="true"
printf "phpstatus:OK "
else
Expand All @@ -63,5 +71,3 @@ fi
rm -f /tmp/healthy

exit 1


2 changes: 1 addition & 1 deletion pkg/versionconstants/versionconstants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var AmplitudeAPIKey = ""
var WebImg = "ddev/ddev-webserver"

// WebTag defines the default web image tag
var WebTag = "v1.23.0-1" // Note that this can be overridden by make
var WebTag = "20240424_stasadev_healthcheck" // Note that this can be overridden by make

// DBImg defines the default db image used for applications.
var DBImg = "ddev/ddev-dbserver"
Expand Down

0 comments on commit ec9b76b

Please sign in to comment.