Created
March 14, 2014 17:41
-
-
Save jrschumacher/9552851 to your computer and use it in GitHub Desktop.
Travis-CI test for MongoDB connectivity before script
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 script will test for MongoDB connectivity. | |
# If MongoDB is available then it continues else it tries X times then fails. | |
# | |
# Use: Add this to your `before_script` option | |
before_script: | |
- | | |
echo "Testing MongoDB connection...";tries=4; | |
i=0; | |
while [ $i -lt $tries ]; do fail=$(mongo --eval db 2>&1 >/dev/null | grep "connect failed"); | |
if [ "$fail" ] && [ $[ $i+1 ] -eq $tries ] ; then echo "Error: Could not connect to mongodb"; exit 1; | |
elif [ "$fail" ]; then sleep 3; i=$[ $i+1 ]; | |
else echo "OK"; i=$tries; fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment