X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fcaas-logging.git;a=blobdiff_plain;f=docker-build%2Felasticsearch%2Fhealthcheck;fp=docker-build%2Felasticsearch%2Fhealthcheck;h=5d1c971e8541f2dfd8b92215ae5d847a993a8f80;hp=0000000000000000000000000000000000000000;hb=229e54ec0c45ee7389247cf6cda79d31b303de85;hpb=9afa6af59d04c80d65eede7fc36b09d370b57abb diff --git a/docker-build/elasticsearch/healthcheck b/docker-build/elasticsearch/healthcheck new file mode 100644 index 0000000..5d1c971 --- /dev/null +++ b/docker-build/elasticsearch/healthcheck @@ -0,0 +1,30 @@ +#!/bin/bash +# Copyright 2019 Nokia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail + +host="$(hostname --ip-address || echo '127.0.0.1')" + +if health="$(curl -fsSL "http://$host:${ELASTICSEARCH_PORT}/_cat/health?h=status")"; then + health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ") + if [ "$health" = 'green' ]; then + exit 0 + fi + echo >&2 "unexpected health status: $health" +fi + +# If the probe returns 2 ("starting") when the container has already moved out of the "starting" state then it is treated as "unhealthy" instead. +# https://github.com/docker/docker/blob/dcc65376bac8e73bb5930fce4cddc2350bb7baa2/docs/reference/builder.md#healthcheck +exit 2