forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·54 lines (46 loc) · 1.27 KB
/
docker-entrypoint.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
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -e
# This script is the entrypoint to the libbeat Docker container. This will
# verify that the Elasticsearch and Redis environment variables are set
# and that Elasticsearch is running before executing the command provided
# to the docker container.
# Read parameters from the environment and validate them.
checkHost() {
if [ -z "$$1" ]; then
echo >&2 'Error: missing required $1 environment variable'
echo >&2 ' Did you forget to -e $1=... ?'
exit 1
fi
}
readParams() {
checkHost "ES_HOST"
# Use default ports if not specified.
: ${ES_PORT:=9200}
}
# Wait for elasticsearch to start. It requires that the status be either
# green or yellow.
waitForElasticsearch() {
echo -n "Waiting on elasticsearch(${ES_HOST}:${ES_PORT}) to start."
for ((i=1;i<=60;i++))
do
health=$(curl --silent "http://${ES_HOST}:${ES_PORT}/_cat/health" | awk '{print $4}')
if [[ "$health" == "green" ]] || [[ "$health" == "yellow" ]]
then
echo
echo "Elasticsearch is ready!"
return 0
fi
((i++))
echo -n '.'
sleep 1
done
echo
echo >&2 'Elasticsearch is not running or is not healthy.'
echo >&2 "Address: ${ES_HOST}:${ES_PORT}"
echo >&2 "$health"
exit 1
}
# Main
readParams
waitForElasticsearch
exec "$@"