Skip to content

Commit 15b0d65

Browse files
committed
added better recognition criteria for es and os
1 parent e8d6fc4 commit 15b0d65

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

dockerfiles/entrypoint-es.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,38 @@ function validate_elasticsearch() {
3030

3131
while [ $retry_count -lt $max_retries ]; do
3232
print_info "Checking Elasticsearch connection (Attempt $((retry_count + 1))/$max_retries)..."
33-
34-
health=$(curl -k -s -o /dev/null -w '%{http_code}' "http://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
33+
34+
local response_body=$(curl -k -s "http://${ES_HOST}:${ES_PORT}/" 2>/dev/null)
35+
local health=$(curl -k -s -o /dev/null -w '%{http_code}' "http://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
3536

3637
if [ "$health" -eq 200 ]; then
37-
print_success "Successfully connected to Elasticsearch via HTTP"
38-
export ES_USE_SSL=false
39-
return 0
38+
if echo "$response_body" | grep -q '"tagline" *: *"You Know, for Search"'; then
39+
print_success "Successfully connected to Elasticsearch via HTTP"
40+
export ES_USE_SSL=false
41+
return 0
42+
else
43+
print_error "Connected to a service that is not Elasticsearch"
44+
print_error "Found service response: $response_body"
45+
return 1
46+
fi
4047
fi
4148

4249
print_info "HTTP connection failed, trying HTTPS..."
50+
response_body=$(curl -k -s "https://${ES_HOST}:${ES_PORT}/" 2>/dev/null)
4351
health=$(curl -s -o /dev/null -w '%{http_code}' "https://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
4452

4553
if [ "$health" -eq 200 ]; then
46-
print_success "Successfully connected to Elasticsearch via HTTPS"
47-
export ES_USE_SSL=true
48-
return 0
54+
if echo "$response_body" | grep -q '"tagline" *: *"You Know, for Search"'; then
55+
print_success "Successfully connected to Elasticsearch via HTTPS"
56+
export ES_USE_SSL=true
57+
return 0
58+
else
59+
print_error "Connected to a service that is not Elasticsearch"
60+
print_error "Found service response: $response_body"
61+
return 1
62+
fi
4963
fi
50-
64+
5165
retry_count=$((retry_count + 1))
5266
if [ $retry_count -lt $max_retries ]; then
5367
print_warning "Connection attempt $retry_count failed. Waiting ${wait_time} seconds before retry..."
@@ -59,7 +73,7 @@ function validate_elasticsearch() {
5973
print_error "Failed to connect to Elasticsearch after $max_retries attempts:"
6074
print_error " - http://${ES_HOST}:${ES_PORT}"
6175
print_error " - https://${ES_HOST}:${ES_PORT}"
62-
print_error "Please ensure:"
76+
print_error " Please ensure:"
6377
print_error " - Elasticsearch is running"
6478
print_error " - ES_HOST and ES_PORT are correctly set"
6579
print_error " - Network connectivity is available"

dockerfiles/entrypoint-os.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,35 @@ function validate_opensearch() {
3131
while [ $retry_count -lt $max_retries ]; do
3232
print_info "Checking OpenSearch connection (Attempt $((retry_count + 1))/$max_retries)..."
3333

34-
health=$(curl -k -s -o /dev/null -w '%{http_code}' "http://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
34+
local response_body=$(curl -k -s "http://${ES_HOST}:${ES_PORT}/" 2>/dev/null)
35+
local health=$(curl -k -s -o /dev/null -w '%{http_code}' "http://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
3536

3637
if [ "$health" -eq 200 ]; then
37-
print_success "Successfully connected to OpenSearch via HTTP"
38-
export ES_USE_SSL=false
39-
return 0
38+
if echo "$response_body" | grep -q '"distribution" *: *"opensearch"'; then
39+
print_success "Successfully connected to OpenSearch via HTTP"
40+
export ES_USE_SSL=false
41+
return 0
42+
else
43+
print_error "Connected to a service that is not OpenSearch"
44+
print_error "Found service response: $response_body"
45+
return 1
46+
fi
4047
fi
4148

4249
print_info "HTTP connection failed, trying HTTPS..."
50+
response_body=$(curl -k -s "https://${ES_HOST}:${ES_PORT}/" 2>/dev/null)
4351
health=$(curl -s -o /dev/null -w '%{http_code}' "https://${ES_HOST}:${ES_PORT}/_cluster/health" 2>/dev/null)
4452

4553
if [ "$health" -eq 200 ]; then
46-
print_success "Successfully connected to OpenSearch via HTTPS"
47-
export ES_USE_SSL=true
48-
return 0
54+
if echo "$response_body" | grep -q '"distribution" *: *"opensearch"'; then
55+
print_success "Successfully connected to OpenSearch via HTTPS"
56+
export ES_USE_SSL=true
57+
return 0
58+
else
59+
print_error "Connected to a service that is not OpenSearch"
60+
print_error "Found service response: $response_body"
61+
return 1
62+
fi
4963
fi
5064

5165
retry_count=$((retry_count + 1))
@@ -64,6 +78,7 @@ function validate_opensearch() {
6478
print_error " - ES_HOST and ES_PORT are correctly set"
6579
print_error " - Network connectivity is available"
6680
print_error " - SSL/TLS settings are correct if using HTTPS"
81+
print_error " - You are not connecting to Elasticsearch or another service"
6782
return 1
6883
}
6984

0 commit comments

Comments
 (0)