Sunday, 5 June 2016

How to check the MongoDB Status in bash script?


is_mongod_running(){
PID=$(cat $MONGODB_HOME/mongod.lock)
        status=$(service mongodb status 2>&1)
        echo $status | grep -q "mongodb start/running, process.*"

        if [ $? -eq 0 ] && [ "x$PID" != "x" ] ;then     #&& kill -0 $PID 2>/dev/null; then
                _status=0 #echo "mongod is running"
        else
                _status=1 #echo "mongod is not running"
        fi
        return $_status
}


Note: Tested under Ubuntu Server 2.x& 14.x

No comments:

Post a Comment