File tree 2 files changed +24
-8
lines changed
2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 47
47
- run :
48
48
command : |
49
49
pushd metacpan-docker/src/metacpan-api
50
- ./wait-for-es.sh elasticsearch_test http://localhost:9200
50
+ ./wait-for-es.sh http://localhost:9200 elasticsearch_test --
51
51
name : wait for ES
52
52
- run :
53
53
command : |
Original file line number Diff line number Diff line change 5
5
6
6
set -ux
7
7
8
- container=" $1 "
9
- host=" $2 "
10
8
11
- preamble=" docker-compose exec $container "
9
+ HOST=" $1 "
10
+ CONTAINER=${2:- " " }
11
+ PREAMBLE=" "
12
+
13
+ echo " container |$CONTAINER |"
14
+ if [[ $CONTAINER != " " ]]; then
15
+ PREAMBLE=" docker-compose exec $CONTAINER "
16
+ fi
12
17
13
18
while true ; do
14
- response=$( $preamble curl --write-out ' %{http_code}' --silent --fail --output /dev/null " $host " )
19
+ response=$( $PREAMBLE curl --write-out ' %{http_code}' --silent --fail --output /dev/null " $HOST " )
15
20
if [[ " $response " -eq " 200" ]]; then
16
21
break
17
22
fi
24
29
# if the server was not available
25
30
set -e
26
31
32
+ COUNTER=0
33
+ MAX_LOOPS=60
27
34
while true ; do
28
35
# # Wait for ES status to turn to yellow.
29
36
# # TODO: Ideally we'd be waiting for green, but we need multiple nodes for that.
30
- health=$( $preamble curl -fsSL " $host /_cat/health?format=JSON" | jq ' .[0].status == "yellow" or .[0].status == "green"' )
37
+ health=$( $PREAMBLE curl -fsSL " $HOST /_cat/health?format=JSON" | jq ' .[0].status == "yellow" or .[0].status == "green"' )
31
38
if [[ $health == ' true' ]]; then
39
+ echo " Elasticsearch is up" >&2
32
40
break
33
41
fi
34
42
echo " Elastic Search is unavailable ($health ) - sleeping" >&2
43
+ COUNTER=$(( COUNTER + 1 ))
44
+ if [[ $COUNTER -gt $MAX_LOOPS ]]; then
45
+ echo " Giving up after $COUNTER attempts"
46
+ exit 1
47
+ break
48
+ fi
35
49
sleep 1
36
50
done
37
51
38
- echo " Elastic Search is up" >&2
39
- exit 0
52
+ # Allow commands to be chained
53
+ shift
54
+ shift
55
+ exec " $@ "
You can’t perform that action at this time.
0 commit comments