Skip to content

Instantly share code, notes, and snippets.

@rivasvict
Created October 14, 2019 00:22
Show Gist options
  • Save rivasvict/681cc56496521faa9e4afb2b6b6d7386 to your computer and use it in GitHub Desktop.
Save rivasvict/681cc56496521faa9e4afb2b6b6d7386 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Lets assume the service is called mongo
MONGO_CONTAINER_ID=''
# Iterate until container id gets defined
while [[ $MONGO_CONTAINER_ID == '' ]]; do
echo "Waiting for container id"
# Attempt to get the mongo container id once
# docker-compose is supposed yo be running
MONGO_CONTAINER_ID=`docker-compose ps -q mongo`
done
# Attempt to check the /var/log/mongodb.log
# file to evaluate whether mongo is ready to
# receive connections or not. This will repeat
# until the command succeds
until docker exec -itd $MONGO_CONTAINER_ID grep -q 'waiting for connections on port' /var/log/mongodb.log; do
echo "Waiting for container to be up"
sleep 0.1
done
# Now run your command here that depends on mongo
# container to be ready to connect
echo "This command depends on mongo receiving connections"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment