Created
June 2, 2017 10:39
-
-
Save ehyland/30eb5cb819d6d2d245b5b2bd0662743a to your computer and use it in GitHub Desktop.
wait for docker entrypoint
This file contains hidden or 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
#!/bin/bash | |
set -e | |
wait_for () { | |
NAME=$1; HOST=$2; PORT=$3; | |
if [ -z "$HOST" ]; then | |
echo "ERROR: $NAME env not set" | |
exit 1 | |
fi | |
until timeout 1 bash -c "cat < /dev/null > /dev/tcp/${HOST}/${PORT}"; do | |
>&2 echo "Waiting for $NAME at \"${HOST}:${PORT}\"..." | |
sleep 1 | |
done | |
echo "$NAME is at up at \"${HOST}:${PORT}\"" | |
} | |
wait_for "IS_UP_RABBIT_HOST" "$IS_UP_RABBIT_HOST" "5672" | |
wait_for "IS_UP_MONGO_HOST" "$IS_UP_MONGO_HOST" "27017" | |
# Run command | |
$@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment