how to check if mongodb is up and ready to accept connections from bash script?

后端 未结 6 1412
眼角桃花
眼角桃花 2020-12-28 20:33

I have a bash shell script which does a bunch of stuff before trying to mongorestore.

I want to make sure that not only MongoDB is up, but it is also re

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-28 20:56

    Possible Docker solution:

    Given the docker_id for me it works reading the docker logs like:

    until [ $(docker logs --tail all $docker_id | grep "waiting for connections on port" | wc -l) -gt 0 ]; do
        printf '.'
        sleep 1
    done
    

    then continue with any mongo-dependent task.

提交回复
热议问题