This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 241
use docker healthcheck #27
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
96c1336
use docker healthcheck
shadiakiki1986 a6d9350
add link to docker file ref
shadiakiki1986 ebfa923
replace --ip-address passed to hostname with -i since the elasticsear…
shadiakiki1986 e3012e0
add not about healthcheck unauthorized error related to xpack
shadiakiki1986 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# Copied from https://github.com/docker-library/healthcheck/tree/master/elasticsearch/docker-healthcheck | ||
# Usage: docker-healthcheck # by default, waits for "green" | ||
# docker-healthcheck yellow # to wait for "yellow" instead | ||
|
||
target='green' | ||
if [ ! -z "$1" ]; then | ||
target="$1" | ||
fi | ||
|
||
set -eo pipefail | ||
|
||
# Use -i instead of --ip-address in case hostname was just a symlink to busybox | ||
# The busybox version of hostname supports -i and not --ip-address | ||
# Both busybox/hostname and the GNU hostname support -i | ||
# References: | ||
# https://busybox.net/downloads/BusyBox.html#hostname | ||
# https://linux.die.net/man/1/hostname | ||
# http://manpages.ubuntu.com/manpages/precise/man1/hostname.1.html | ||
host="$(hostname -i || echo '127.0.0.1')" | ||
|
||
# TODO with xpack, the below curl will fail with "unauthorized" error if xpack is enabled | ||
if health="$(curl -fsSL "http://$host:9200/_cat/health?h=status")"; then | ||
health="$(echo "$health" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g')" # trim whitespace (otherwise we'll have "green ") | ||
if [ "$health" = "$target" ]; then | ||
exit 0 | ||
fi | ||
echo >&2 "unexpected health status: $health" | ||
fi | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if you get a 401/403 response code, this means container is healthy
you could call
curl -I -X "http://$host:9200"
and parse response code