From 5d2839a43b66bd1c326e0e85fc9e5ee1cb2d7afa Mon Sep 17 00:00:00 2001 From: Hasnat Ullah Date: Mon, 3 Jun 2019 20:14:28 +0100 Subject: [PATCH] More appropriate self healthcheck --- Dockerfile | 2 +- docker-entrypoint | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ae825de..1ab87d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ RUN apk add --no-cache curl jq COPY docker-entrypoint / ENTRYPOINT ["/docker-entrypoint"] -HEALTHCHECK --interval=5s CMD exit 0 +HEALTHCHECK --interval=5s CMD /docker-entrypoint healthcheck CMD ["autoheal"] diff --git a/docker-entrypoint b/docker-entrypoint index a1bf8ab..67f092d 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -12,11 +12,17 @@ term_handler() { } docker_curl() { - curl --max-time "${CURL_TIMEOUT}" --no-buffer -s --unix-socket "${DOCKER_SOCK}" "$@" + curl --max-time "${CURL_TIMEOUT}" --no-buffer -s --unix-socket "${DOCKER_SOCK}" "$@" || return 1 + return 0 } trap 'kill ${!}; term_handler' SIGTERM +if [ "$1" = 'healthcheck' ]; then + docker_curl --fail http://localhost/_ping + exit $? +fi + if [ "$1" = 'autoheal' ] && [ -e ${DOCKER_SOCK} ]; then # https://docs.docker.com/engine/api/v1.25/