Skip to content

Commit

Permalink
wait for mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jul 30, 2023
1 parent 22316b1 commit 0328a43
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions start-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ MONGODB_DB=$4
MONGODB_USERNAME=$5
MONGODB_PASSWORD=$6

wait_for_mongodb () {
echo "::group::Waiting for MongoDB to accept connections"
sleep 1
TIMER=0

until docker exec --tty mongodb $MONGO_CLIENT --port $MONGODB_PORT --eval "db.serverStatus()" # &> /dev/null
do
sleep 1
echo "."
TIMER=$((TIMER + 1))

if [[ $TIMER -eq 20 ]]; then
echo "MongoDB did not initialize within 20 seconds. Exiting."
exit 2
fi
done
echo "::endgroup::"
}

if [ -z "$MONGODB_VERSION" ]; then
echo ""
Expand Down Expand Up @@ -45,6 +63,8 @@ if [ -z "$MONGODB_REPLICA_SET" ]; then
fi
echo "::endgroup::"

wait_for_mongodb

return
fi

Expand All @@ -63,24 +83,7 @@ if [ $? -ne 0 ]; then
fi
echo "::endgroup::"


echo "::group::Waiting for MongoDB to accept connections"
sleep 1
TIMER=0

until docker exec --tty mongodb $MONGO_CLIENT --port $MONGODB_PORT --eval "db.serverStatus()" # &> /dev/null
do
sleep 1
echo "."
TIMER=$((TIMER + 1))

if [[ $TIMER -eq 20 ]]; then
echo "MongoDB did not initialize within 20 seconds. Exiting."
exit 2
fi
done
echo "::endgroup::"

wait_for_mongodb

echo "::group::Initiating replica set [$MONGODB_REPLICA_SET]"

Expand Down

0 comments on commit 0328a43

Please sign in to comment.