Skip to content

Instantly share code, notes, and snippets.

@ehyland
Created June 2, 2017 10:39
Show Gist options
  • Save ehyland/30eb5cb819d6d2d245b5b2bd0662743a to your computer and use it in GitHub Desktop.
Save ehyland/30eb5cb819d6d2d245b5b2bd0662743a to your computer and use it in GitHub Desktop.
wait for docker entrypoint
#!/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