Skip to content

Commit a0c3903

Browse files
committed
feat(elasticsearch): Add optional healthcheck script
1 parent 9c254fc commit a0c3903

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

build/Elasticsearch/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN \
1212
org.wikimedia.search:extra:${ELASTICSEARCH_PLUGIN_WIKIMEDIA_EXTRA} && \
1313
./bin/elasticsearch-plugin install \
1414
org.wikimedia.search.highlighter:experimental-highlighter-elasticsearch-plugin:${ELASTICSEARCH_PLUGIN_WIKIMEDIA_HIGHLIGHTER}
15+
COPY healthcheck.sh /healthcheck.sh
1516
COPY default.jvm.options /default.jvm.options
1617
RUN cat /default.jvm.options >> /usr/share/elasticsearch/config/jvm.options && \
1718
rm /default.jvm.options
18-

build/Elasticsearch/README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,22 @@ services:
4646
DB_USER: "mariadb-user"
4747
DB_PASS: "change-this-password"
4848
ELASTICSEARCH_HOST: elasticsearch
49-
healthcheck:
50-
test: curl --silent --fail localhost/wiki/Main_Page
51-
interval: 10s
52-
start_period: 5m
5349
depends_on:
5450
mysql:
5551
condition: service_healthy
5652
restart: unless-stopped
53+
healthcheck: /healthcheck.sh
5754

5855
wikibase-jobrunner:
5956
image: wikibase/wikibase
6057
volumes_from:
6158
- wikibase
62-
command: /jobrunner-entrypoint.sh
6359
depends_on:
6460
wikibase:
6561
condition: service_healthy
6662
restart: always
63+
environment:
64+
IS_JOBRUNNER: true
6765

6866
mysql:
6967
image: mariadb:10.11
@@ -89,10 +87,7 @@ services:
8987
environment:
9088
discovery.type: single-node
9189
ES_JAVA_OPTS: -Xms512m -Xmx512m -Dlog4j2.formatMsgNoLookups=true
92-
healthcheck:
93-
test: curl --silent --fail localhost:9200
94-
interval: 10s
95-
start_period: 2m
90+
healthcheck: /healthcheck.sh
9691

9792
volumes:
9893
wikibase-image-data:

build/Elasticsearch/healthcheck.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Ref. https://github.com/docker-library/healthcheck/blob/master/elasticsearch/docker-healthcheck
4+
5+
set -eo pipefail
6+
7+
host="$(hostname --ip-address || echo '127.0.0.1')"
8+
9+
if health="$(curl -fsSL "http://$host:9200/_cat/health?h=status")"; then
10+
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ")
11+
if [ "$health" = 'green' ]; then
12+
exit 0
13+
fi
14+
echo >&2 "unexpected health status: $health"
15+
fi
16+
17+
exit 1

0 commit comments

Comments
 (0)