Skip to content

Commit d8e8962

Browse files
authored
Merge pull request #950 from metacpan/oalders/wait-for-es
Add wait-for-es script
2 parents bf98ed2 + 04574c1 commit d8e8962

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
PGDB=db:5432
1+
PGDB=pgdb:5432
22
API_SERVER=morbo -l http://*:5000 -w app.psgi -w bin -w lib -w templates --verbose

wait-for-es.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Courtesy of @fxdgear
4+
# https://github.com/elastic/elasticsearch-py/issues/778#issuecomment-384389668
5+
6+
set -e
7+
8+
host="$1"
9+
shift
10+
cmd="$@"
11+
12+
13+
until $(curl --output /dev/null --silent --head --fail "$host"); do
14+
printf '.'
15+
sleep 1
16+
done
17+
18+
# First wait for ES to start...
19+
response=$(curl $host)
20+
21+
until [ "$response" = "200" ]; do
22+
response=$(curl --write-out %{http_code} --silent --output /dev/null "$host")
23+
>&2 echo "Elastic Search is unavailable - sleeping"
24+
sleep 1
25+
done
26+
27+
28+
# Wait for ES status to turn to yellow.
29+
# TODO: Ideally we'd be waiting for green, but we need multiple nodes for that.
30+
31+
health="$(curl -fsSL "$host/_cat/health?h=status")"
32+
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
33+
34+
until [ "$health" = 'yellow' ]; do
35+
health="$(curl -fsSL "$host/_cat/health?h=status")"
36+
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
37+
>&2 echo "Elastic Search is unavailable ($health) - sleeping"
38+
sleep 1
39+
done
40+
41+
>&2 echo "Elastic Search is up"
42+
exec $cmd

0 commit comments

Comments
 (0)