From 5cf76fe7d61d23c0b2566951b4effe84fddb04a2 Mon Sep 17 00:00:00 2001 From: lgromero Date: Thu, 28 Aug 2025 09:16:25 +0200 Subject: [PATCH] refs #2646 check and wait por opensearch plugin security and for green or yellow cluster of opensearch --- debian/oglog.postinst | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/debian/oglog.postinst b/debian/oglog.postinst index 97a8233..46fe770 100755 --- a/debian/oglog.postinst +++ b/debian/oglog.postinst @@ -291,7 +291,55 @@ restart_services() { systemctl restart prometheus systemctl restart systemd-journal-remote } +wait_for_opensearch_cluster() { + local MAX_WAIT=120 + local WAIT_INTERVAL=2 + local ELAPSED=0 + local HEALTH_URL="https://${OGLOG_SERVER}:9200/_cluster/health?wait_for_status=yellow&timeout=1s" + echo "Waiting for OpenSearch cluster to reach yellow or green status..." + while [ $ELAPSED -lt $MAX_WAIT ]; do + RESPONSE=$(curl --insecure -s --user "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" "$HEALTH_URL") + if echo "$RESPONSE" | jq -e . >/dev/null 2>&1; then + STATUS=$(echo "$RESPONSE" | jq -r '.status') + if [[ "$STATUS" == "yellow" || "$STATUS" == "green" ]]; then + echo "Cluster status is $STATUS. Proceeding." + return 0 + fi + else + echo "OpenSearch Security not initialized or invalid response: $RESPONSE" + fi + sleep $WAIT_INTERVAL + ELAPSED=$((ELAPSED + WAIT_INTERVAL)) + done + echo "Failed to reach yellow or green status for OpenSearch cluster after $MAX_WAIT seconds." + return 1 +} + +wait_for_opensearch_plugin() { + local MAX_WAIT=120 + local WAIT_INTERVAL=2 + local ELAPSED=0 + local PLUGIN_URL="https://${OGLOG_SERVER}:9200/_plugins/_security/health" + + echo "Waiting for OpenSearch security plugin to be UP..." + while [ $ELAPSED -lt $MAX_WAIT ]; do + RESPONSE=$(curl --insecure -s --user "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" "$PLUGIN_URL") + if echo "$RESPONSE" | jq -e . >/dev/null 2>&1; then + STATUS=$(curl --insecure -s --user "admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD" "$PLUGIN_URL" | jq -r '.status') + if [[ "$STATUS" == "UP" ]]; then + echo "Security plugin status is UP. Proceeding." + return 0 + fi + else + echo "OpenSearch Security not initialized or invalid response: $RESPONSE" + fi + sleep $WAIT_INTERVAL + ELAPSED=$((ELAPSED + WAIT_INTERVAL)) + done + echo "Failed to reach UP status for OpenSearch security plugin after $MAX_WAIT seconds." + return 1 +} case $1 in configure) PREV_VERSION="$2" @@ -318,6 +366,8 @@ case $1 in configure_prometheus restart_services sleep 5 + wait_for_opensearch_cluster + wait_for_opensearch_plugin echo "Creating OpenSearch index patterns and initial index..." create_opensearch_index else