forked from deviantony/docker-elk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
travis: Move reusable functions to bash lib
- Loading branch information
Showing
4 changed files
with
59 additions
and
54 deletions.
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,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
function log { | ||
echo -e "\n[+] $1\n" | ||
} | ||
|
||
function poll_ready { | ||
local svc=$1 | ||
local url=$2 | ||
|
||
local -a args=( '-s' '-D-' '-w' '%{http_code}' "$url" ) | ||
if [ "$#" -ge 3 ]; then | ||
args+=( '-u' "$3" ) | ||
fi | ||
|
||
local label | ||
if [ "$MODE" == "swarm" ]; then | ||
label="com.docker.swarm.service.name=elk_${svc}" | ||
else | ||
label="com.docker.compose.service=${svc}" | ||
fi | ||
|
||
local -i result=1 | ||
local cid | ||
local output | ||
|
||
# retry for max 120s (24*5s) | ||
for _ in $(seq 1 24); do | ||
cid="$(docker ps -q -f label="$label")" | ||
if [ -z "${cid:-}" ]; then | ||
echo "Container exited" | ||
return 1 | ||
fi | ||
|
||
set +e | ||
output="$(curl "${args[@]}")" | ||
set -e | ||
if [ "${output: -3}" -eq 200 ]; then | ||
result=0 | ||
break | ||
fi | ||
|
||
echo -n '.' | ||
sleep 5 | ||
done | ||
|
||
echo -e "\n${output::-3}" | ||
|
||
return $result | ||
} |
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