Skip to content

Commit

Permalink
refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jul 31, 2023
1 parent ddb09f8 commit 227b945
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions start-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@ MONGODB_DB=$4
MONGODB_USERNAME=$5
MONGODB_PASSWORD=$6

wait_for_mongodb () {
echo "::group::Waiting for MongoDB to accept connections"
sleep 1
TIMER=0
# `mongosh` is used starting from MongoDB 5.x
MONGODB_CLIENT="mongosh --quiet"

until docker exec --tty mongodb $MONGO_CLIENT --eval "db.serverStatus()" # &> /dev/null
do
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 All @@ -38,14 +24,33 @@ fi
echo "::group::Selecting correct MongoDB client"
if [ "`echo $MONGODB_VERSION | cut -c 1`" = "4" ]; then
MONGO_CLIENT="mongo"
else
MONGO_CLIENT="mongosh --quiet"
fi
echo " - Using [$MONGO_CLIENT]"
echo ""
echo "::endgroup::"


# Helper function to wait for MongoDB to be started before moving on
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()"
do
echo "."
sleep 1
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_REPLICA_SET" ]; then
echo "::group::Starting single-node instance, no replica set"
echo " - port [$MONGODB_PORT]"
Expand Down

0 comments on commit 227b945

Please sign in to comment.