-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathsetup-cassandra-es.sh
More file actions
executable file
·61 lines (56 loc) · 2.84 KB
/
setup-cassandra-es.sh
File metadata and controls
executable file
·61 lines (56 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
set -eu
# Validate required environment variables
: "${ES_SCHEME:?ERROR: ES_SCHEME environment variable is required}"
: "${ES_HOST:?ERROR: ES_HOST environment variable is required}"
: "${ES_PORT:?ERROR: ES_PORT environment variable is required}"
: "${ES_VISIBILITY_INDEX:?ERROR: ES_VISIBILITY_INDEX environment variable is required}"
: "${ES_VERSION:?ERROR: ES_VERSION environment variable is required}"
: "${CASSANDRA_SEEDS:?ERROR: CASSANDRA_SEEDS environment variable is required}"
echo 'Starting Cassandra and Elasticsearch schema setup...'
echo 'Waiting for Cassandra port to be available...'
nc -z -w 10 ${CASSANDRA_SEEDS} 9042
echo 'Cassandra port is available'
echo 'Waiting for Cassandra to be ready...'
until temporal-cassandra-tool --ep ${CASSANDRA_SEEDS} validate-health; do
echo 'Cassandra not ready yet, waiting...'
sleep 2
done
echo 'Cassandra is ready'
# Create and setup Cassandra keyspace
temporal-cassandra-tool --ep ${CASSANDRA_SEEDS} create -k temporal --rf 1
temporal-cassandra-tool --ep ${CASSANDRA_SEEDS} -k temporal setup-schema -v 0.0
temporal-cassandra-tool --ep ${CASSANDRA_SEEDS} -k temporal update-schema -d /etc/temporal/schema/cassandra/temporal/versioned
# Setup Elasticsearch index
# temporal-elasticsearch-tool is available in v1.30+ server releases
if [ -x /usr/local/bin/temporal-elasticsearch-tool ]; then
echo 'Using temporal-elasticsearch-tool for Elasticsearch setup'
temporal-elasticsearch-tool --ep "$ES_SCHEME://$ES_HOST:$ES_PORT" setup-schema
temporal-elasticsearch-tool --ep "$ES_SCHEME://$ES_HOST:$ES_PORT" create-index --index $ES_VISIBILITY_INDEX
else
echo 'Using curl for Elasticsearch setup'
echo 'WARNING: curl will be removed from admin-tools in v1.30.'
echo 'Waiting for Elasticsearch to be ready...'
max_attempts=30
attempt=0
until curl -s -f "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s"; do
attempt=$((attempt + 1))
if [ $attempt -ge $max_attempts ]; then
echo "ERROR: Elasticsearch did not become ready after $max_attempts attempts"
echo "Last error from curl:"
curl "$ES_SCHEME://$ES_HOST:$ES_PORT/_cluster/health?wait_for_status=yellow&timeout=1s" 2>&1 || true
exit 1
fi
echo "Elasticsearch not ready yet, waiting... (attempt $attempt/$max_attempts)"
sleep 2
done
echo ''
echo 'Elasticsearch is ready'
echo 'Creating index template...'
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"
echo ''
echo 'Creating index...'
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"
echo ''
fi
echo 'Cassandra and Elasticsearch setup complete'