From 1df66bee026c53ffa0e0369c869d47b89798ed5a Mon Sep 17 00:00:00 2001 From: Markus Date: Wed, 14 Aug 2024 11:41:30 +0300 Subject: [PATCH] move variable to right scope --- .../elasticsearch/setup-elastalert-indices.sh | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/infrastructure/elasticsearch/setup-elastalert-indices.sh b/infrastructure/elasticsearch/setup-elastalert-indices.sh index 22d0787c7..69b772c19 100755 --- a/infrastructure/elasticsearch/setup-elastalert-indices.sh +++ b/infrastructure/elasticsearch/setup-elastalert-indices.sh @@ -34,30 +34,19 @@ indices='elastalert_status,elastalert_status_error,elastalert_status_past,elasta bulk_delete_status_code=$($docker_command --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -o /dev/null -w '%{http_code}' "http://elasticsearch:9200/${indices}" -X DELETE) -<<<<<<< HEAD -if [ "$delete_status_code" -ne 200 ]; then - echo "Could not delete indices. API returned status code: $delete_status_code" - exit 1 -fi - -echo 'Scaling up Elastalert' -docker service scale opencrvs_elastalert=1 - -======= if [ "$bulk_delete_status_code" -ne 200 ]; then echo "Could not delete indices. API returned status code: $bulk_delete_status_code" fi + +non_404_error_when_deleting_one_by_one=0 + if [ "$bulk_delete_status_code" -eq 404 ]; then echo "Some of the indices do not exist. Attempting to delete them one by one." - + # Convert the comma-separated indices into an array IFS=',' read -r -a indices_array <<< "$indices" - - - non_404_error_when_deleting_one_by_one=0 - for index in "${indices_array[@]}"; do echo "Deleting index: $index" individual_delete_status_code=$($docker_command --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -o /dev/null -w '%{http_code}' "http://elasticsearch:9200/${index}" -X DELETE) @@ -81,5 +70,4 @@ if [ "$non_404_error_when_deleting_one_by_one" -eq 0 ] && { [ "$bulk_delete_stat exit 0 fi -exit 1 - +exit 1 \ No newline at end of file