Add healthcheck endpoints (#5543)

This PR adds readiness and liveness endpoints to probe Minio server
instance health. Endpoints can only be accessed without authentication
and the paths are /minio/health/live and /minio/health/ready for
liveness and readiness respectively.

The new healthcheck liveness endpoint is used for Docker healthcheck
now.

Fixes #5357
Fixes #5514
This commit is contained in:
Nitish Tiwari
2018-03-12 11:46:53 +05:30
committed by GitHub
parent d90985b6d8
commit 10b01ac836
7 changed files with 217 additions and 11 deletions

View File

@@ -20,7 +20,7 @@ set -x
_init () {
scheme="http://"
address="$(netstat -nplt 2>/dev/null | awk ' /(.*\/minio)/ { gsub(":::","127.0.0.1:",$4); print $4}')"
resource="/minio/index.html"
resource="/minio/health/live"
start=$(stat -c "%Y" /proc/1)
}
@@ -34,11 +34,10 @@ healthcheck_main () {
exit 0
else
# Get the http response code
http_response=$(curl -H "User-Agent: Mozilla" -s -k -o /dev/null -I -w "%{http_code}" \
${scheme}${address}${resource})
http_response=$(curl -s -k -o /dev/null -I -w "%{http_code}" ${scheme}${address}${resource})
# Get the http response body
http_response_body=$(curl -H "User-Agent: Mozilla" -k -s ${scheme}${address}${resource})
http_response_body=$(curl -k -s ${scheme}${address}${resource})
# server returns response 403 and body "SSL required" if non-TLS
# connection is attempted on a TLS-configured server. Change
@@ -46,14 +45,11 @@ healthcheck_main () {
if [ "$http_response" = "403" ] && \
[ "$http_response_body" = "SSL required" ]; then
scheme="https://"
http_response=$(curl -H "User-Agent: Mozilla" -s -k -o /dev/null -I -w "%{http_code}" \
${scheme}${address}${resource})
http_response=$(curl -s -k -o /dev/null -I -w "%{http_code}" ${scheme}${address}${resource})
fi
# If http_repsonse is 200 - server is up. When MINIO_BROWSER is
# set to off, curl responds with 404. We assume that the server
# is up
[ "$http_response" = "200" ] || [ "$http_response" = "404" ]
# If http_repsonse is 200 - server is up.
[ "$http_response" = "200" ]
fi
}