-
Notifications
You must be signed in to change notification settings - Fork 3
/
elastic.sh
executable file
·44 lines (34 loc) · 1.48 KB
/
elastic.sh
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
#!/bin/bash
# (C) Copyright IBM Corp. 2020
#
# SPDX-License-Identifier: Apache-2.0
echo "Looking up ElasticSearch connection information and credentials"
# Get Elastic connection info
id=$(ibmcloud resource service-instance "${ELASTIC_INSTANCE}" --output json | jq .[0].id)
echo
echo "ES id: $id"
ibmcloud resource service-key "${ELASTIC_SVC_ACCOUNT}" --output json | jq ".[] | select(.source_crn == $id) | .credentials.connection.https.certificate.certificate_base64" | tr -d '"' | base64 -d > elastic.crt
export CURL_CA_BUNDLE=elastic.crt
baseUrl=$(ibmcloud resource service-key "${ELASTIC_SVC_ACCOUNT}" --output json | jq ".[] | select(.source_crn == $id) | .credentials.connection.https.composed[0]" | tr -d '"')
echo
# Remove the credentials from the url when logging
echo "ES baseUrl: ${baseUrl/:\/\/*@/://}"
# Keep track of any failures
rtn=0
# set auto-index creation off
echo
echo "Setting ElasticSearch auto index creation to false"
curl -X PUT -sS -f $baseUrl/_cluster/settings -H 'Content-Type: application/json' -d'
{
"persistent": { "action.auto_create_index": "false" }
}' || { echo 'Setting ElasticSearch auto index creation failed!' ; rtn=1; }
# upload batches index template
echo
echo "Setting ElasticSearch Batches index template"
curl -X PUT -sS -f $baseUrl/_index_template/batches -H 'Content-Type: application/json' -d '@batches.json' ||
{
echo -e '\nSetting ElasticSearch Batches index template failed!' ; rtn=1;
}
echo
echo "ElasticSearch configuration complete"
exit $rtn