refs #2646 check and wait por opensearch plugin security and for green or yellow cluster of opensearch

pull/5/head
Luis Gerardo Romero Garcia 2025-08-28 09:16:25 +02:00
parent 365c14dc93
commit 5cf76fe7d6
1 changed files with 50 additions and 0 deletions

50
debian/oglog.postinst vendored
View File

@ -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