Created
September 14, 2016 04:14
-
-
Save pitervergara/0e5dc66890e6a7e5b96c8ead6d91fc37 to your computer and use it in GitHub Desktop.
Docker entrypoint to test and wait for service dependencies
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
| ```bash | |
| #!/bin/bash | |
| # List all deps using this format: ("host port", "host port"). Remember to link the container using the 'host' name. | |
| requirements=("postgis 5432" "redis 6379" "elasticsearch 9200") | |
| cmd="$@" | |
| missing_requirement=true | |
| while [ "${missing_requirement}" == "true" ] | |
| do | |
| missing_requirement=false | |
| sleep 1 | |
| for req in "${requirements[@]}" | |
| do | |
| if ! nc -z $req | |
| then | |
| echo "Waiting for ${req} to be up" | |
| missing_requirement=true | |
| else | |
| echo "${req} is up!" | |
| fi | |
| done | |
| done | |
| >&2 echo "All required services are up. Let's move on..!" | |
| exec $cmd | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment