From 083c9498c6dc09e0c096da8c43081d5a8a64170c Mon Sep 17 00:00:00 2001 From: Steven Fitzpatrick Date: Mon, 13 Jul 2020 16:24:36 -0500 Subject: [PATCH] Elasticsearch: Improve logging in cluster wait The cluster wait function can sometimes receive an invalid response, and this would "pass" the status check condition. This change prints the response to make it more clear what occured, and changes the condition to explicitly wait for a "yellow" or "green" status. Change-Id: Ifd1267a5fa19acbc6bc8bba65b1ba41409a584a3 --- elasticsearch/templates/bin/_es-cluster-wait.sh.tpl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/elasticsearch/templates/bin/_es-cluster-wait.sh.tpl b/elasticsearch/templates/bin/_es-cluster-wait.sh.tpl index d4ae9ac11..d853503cd 100644 --- a/elasticsearch/templates/bin/_es-cluster-wait.sh.tpl +++ b/elasticsearch/templates/bin/_es-cluster-wait.sh.tpl @@ -14,13 +14,15 @@ limitations under the License. */}} function check_cluster_health() { - STATUS=$(curl -s -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ - "${ELASTICSEARCH_HOST}/_cat/health?format=json&pretty" | jq -r .[].status) + RESPONSE=$(curl -s -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ + "${ELASTICSEARCH_HOST}/_cat/health?format=json&pretty" ) + echo "Response: $RESPONSE" + STATUS=$(echo $RESPONSE | jq -r .[].status) echo "Status: $STATUS" } check_cluster_health -while [[ $STATUS == "red" ]]; do +while [[ $STATUS != "yellow" ]] && [[ $STATUS != "green" ]]; do echo "Waiting for cluster to become ready." sleep 30 check_cluster_health