Skip to content

Commit 9e4be78

Browse files
committed
update es error handling
1 parent 5e6fb7f commit 9e4be78

5 files changed

Lines changed: 100 additions & 15 deletions

File tree

compose/scripts/setup-cassandra-es.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,28 @@ if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
3333
else
3434
echo 'Using curl for Elasticsearch setup'
3535
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
36-
echo 'Waiting for Elasticsearch port to be available...'
37-
nc -z -w 10 $ES_HOST $ES_PORT
38-
echo 'Elasticsearch port is available'
36+
echo 'Waiting for Elasticsearch to be ready...'
37+
max_attempts=30
38+
attempt=0
39+
until curl -s -f "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
40+
attempt=$((attempt + 1))
41+
if [ $attempt -ge $max_attempts ]; then
42+
echo "ERROR: Elasticsearch did not become ready after $max_attempts attempts"
43+
echo "Last error from curl:"
44+
curl "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
45+
exit 1
46+
fi
47+
echo "Elasticsearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
48+
sleep 2
49+
done
50+
echo ''
51+
echo 'Elasticsearch is ready'
52+
echo 'Creating index template...'
3953
curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/_template/temporal_visibility_v1_template" -H 'Content-Type: application/json' --data-binary "@/etc/temporal/schema/elasticsearch/visibility/index_template_$ES_VERSION.json"
54+
echo ''
55+
echo 'Creating index...'
4056
curl --head --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX" 2>/dev/null || curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX"
57+
echo ''
4158
fi
4259

4360
echo 'Cassandra and Elasticsearch setup complete'

compose/scripts/setup-mysql-es.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@ if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
2727
else
2828
echo 'Using curl for Elasticsearch setup'
2929
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
30-
echo 'Waiting for Elasticsearch port to be available...'
31-
nc -z -w 10 $ES_HOST $ES_PORT
32-
echo 'Elasticsearch port is available'
30+
echo 'Waiting for Elasticsearch to be ready...'
31+
max_attempts=30
32+
attempt=0
33+
until curl -s -f "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
34+
attempt=$((attempt + 1))
35+
if [ $attempt -ge $max_attempts ]; then
36+
echo "ERROR: Elasticsearch did not become ready after $max_attempts attempts"
37+
echo "Last error from curl:"
38+
curl "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
39+
exit 1
40+
fi
41+
echo "Elasticsearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
42+
sleep 2
43+
done
44+
echo ''
45+
echo 'Elasticsearch is ready'
46+
echo 'Creating index template...'
3347
curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/_template/temporal_visibility_v1_template" -H 'Content-Type: application/json' --data-binary "@/etc/temporal/schema/elasticsearch/visibility/index_template_$ES_VERSION.json"
48+
echo ''
49+
echo 'Creating index...'
3450
curl --head --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX" 2>/dev/null || curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX"
51+
echo ''
3552
fi
3653

3754
echo 'MySQL and Elasticsearch setup complete'

compose/scripts/setup-postgres-es-tls.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,28 @@ if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
3030
else
3131
echo 'Using curl for Elasticsearch setup'
3232
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
33-
echo 'Waiting for Elasticsearch port to be available...'
34-
nc -z -w 10 $ES_HOST $ES_PORT
35-
echo 'Elasticsearch port is available'
33+
echo 'Waiting for Elasticsearch to be ready...'
34+
max_attempts=30
35+
attempt=0
36+
until curl -s -f -k -u "$ES_USER:$ES_PWD" "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
37+
attempt=$((attempt + 1))
38+
if [ $attempt -ge $max_attempts ]; then
39+
echo "ERROR: Elasticsearch did not become ready after $max_attempts attempts"
40+
echo "Last error from curl:"
41+
curl -k -u "$ES_USER:$ES_PWD" "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
42+
exit 1
43+
fi
44+
echo "Elasticsearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
45+
sleep 2
46+
done
47+
echo ''
48+
echo 'Elasticsearch is ready'
49+
echo 'Creating index template...'
3650
curl -X PUT --fail -k -u "$ES_USER:$ES_PWD" "$ES_SCHEME://$ES_HOST:$ES_PORT/_template/temporal_visibility_v1_template" -H 'Content-Type: application/json' --data-binary "@/etc/temporal/schema/elasticsearch/visibility/index_template_$ES_VERSION.json"
51+
echo ''
52+
echo 'Creating index...'
3753
curl -k -u "$ES_USER:$ES_PWD" --head --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX" 2>/dev/null || curl -k -u "$ES_USER:$ES_PWD" -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX"
54+
echo ''
3855
fi
3956

4057
echo 'PostgreSQL and Elasticsearch (TLS) setup complete'

compose/scripts/setup-postgres-es.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@ if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
2727
else
2828
echo 'Using curl for Elasticsearch setup'
2929
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
30-
echo 'Waiting for Elasticsearch port to be available...'
31-
nc -z -w 10 $ES_HOST $ES_PORT
32-
echo 'Elasticsearch port is available'
30+
echo 'Waiting for Elasticsearch to be ready...'
31+
max_attempts=30
32+
attempt=0
33+
until curl -s -f "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
34+
attempt=$((attempt + 1))
35+
if [ $attempt -ge $max_attempts ]; then
36+
echo "ERROR: Elasticsearch did not become ready after $max_attempts attempts"
37+
echo "Last error from curl:"
38+
curl "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
39+
exit 1
40+
fi
41+
echo "Elasticsearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
42+
sleep 2
43+
done
44+
echo ''
45+
echo 'Elasticsearch is ready'
46+
echo 'Creating index template...'
3347
curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/_template/temporal_visibility_v1_template" -H 'Content-Type: application/json' --data-binary "@/etc/temporal/schema/elasticsearch/visibility/index_template_$ES_VERSION.json"
48+
echo ''
49+
echo 'Creating index...'
3450
curl --head --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX" 2>/dev/null || curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX"
51+
echo ''
3552
fi
3653

3754
echo 'PostgreSQL and Elasticsearch setup complete'

compose/scripts/setup-postgres-opensearch.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@ if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
2727
else
2828
echo 'Using curl for OpenSearch setup'
2929
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
30-
echo 'Waiting for OpenSearch port to be available...'
31-
nc -z -w 10 $ES_HOST $ES_PORT
32-
echo 'OpenSearch port is available'
30+
echo 'Waiting for OpenSearch to be ready...'
31+
max_attempts=30
32+
attempt=0
33+
until curl -s -f "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
34+
attempt=$((attempt + 1))
35+
if [ $attempt -ge $max_attempts ]; then
36+
echo "ERROR: OpenSearch did not become ready after $max_attempts attempts"
37+
echo "Last error from curl:"
38+
curl "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
39+
exit 1
40+
fi
41+
echo "OpenSearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
42+
sleep 2
43+
done
44+
echo ''
45+
echo 'OpenSearch is ready'
46+
echo 'Creating index template...'
3347
curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/_template/temporal_visibility_v1_template" -H 'Content-Type: application/json' --data-binary "@/etc/temporal/schema/elasticsearch/visibility/index_template_$ES_VERSION.json"
48+
echo ''
49+
echo 'Creating index...'
3450
curl --head --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX" 2>/dev/null || curl -X PUT --fail "$ES_SCHEME://$ES_HOST:$ES_PORT/$ES_VISIBILITY_INDEX"
51+
echo ''
3552
fi
3653

3754
echo 'PostgreSQL and OpenSearch setup complete'

0 commit comments

Comments
 (0)