File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 4747 - run :
4848 command : |
4949 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 --
5151 name : wait for ES
5252 - run :
5353 command : |
Original file line number Diff line number Diff line change 55
66set -ux
77
8- container=" $1 "
9- host=" $2 "
108
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
1217
1318while 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 " )
1520 if [[ " $response " -eq " 200" ]]; then
1621 break
1722 fi
2429# if the server was not available
2530set -e
2631
32+ COUNTER=0
33+ MAX_LOOPS=60
2734while true ; do
2835 # # Wait for ES status to turn to yellow.
2936 # # 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"' )
3138 if [[ $health == ' true' ]]; then
39+ echo " Elasticsearch is up" >&2
3240 break
3341 fi
3442 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
3549 sleep 1
3650done
3751
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