forked from elastic/elasticsearch-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait-for-elasticsearch.sh
37 lines (27 loc) · 941 Bytes
/
wait-for-elasticsearch.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
#!/bin/bash
set -e
host="$1"
shift
cmd="$@"
until $(curl --output /dev/null --silent --head --fail "$host"); do
printf '.'
sleep 1
done
# First wait for ES to start...
response=$(curl $host)
until [ "$response" = "200" ]; do
response=$(curl --write-out %{http_code} --silent --output /dev/null "$host")
>&2 echo "Elasticsearch is unavailable - sleeping"
sleep 1
done
# next wait for ES status to turn to Green
health="$(curl -fsSL "$host/_cat/health?h=status")"
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
until [ "$health" = 'green' ]; do
health="$(curl -fsSL "$host/_cat/health?h=status")"
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
>&2 echo "Elasticsearch is unavailable - sleeping"
sleep 1
done
>&2 echo "Elasticsearch is up"
exec $cmd