Showing posts with label mongo. Show all posts
Showing posts with label mongo. Show all posts

Sunday, 5 June 2016

How to repair the MongoDB with bash script?


repair_and_restart_mongod(){

  if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi

  ENABLE_MONGODB="yes"
  if [ "x$ENABLE_MONGODB" = "xyes" ]; then
        if [ -f $MONGODB_HOME/mongod.lock ]; then
                rm $MONGODB_HOME/mongod.lock >> /dev/null
                sudo -u mongodb /usr/bin/mongod --config /etc/mongodb.conf --repair >> /dev/null
        fi
        #exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf
        service mongodb start >> /dev/null  2>&1
  fi
}

Tested under Ubuntu Server 12.x& 14.x

Friday, 3 June 2016

How to check MongoDB is running with linux shell script?


#!/bin/bash

if pgrep mongod >>/dev/null ;then
    echo "Mongo DB Server is Running"
else
    echo "Mongo DB Server is not Running"
fi


Explanation: pgrep is signal process, it looks through running process and list the process id' s that matches the name of the process.