start / stop script for mongodb

Mongodb didn’t come with a start up script, at least not on ubuntu.

Below is the start-up script I am using, it uses a config file /etc/mongodb.conf

My settings in the conf file are just some basics listed below:

port=27017
replSet=foo
dbpath=/data/db
logpath=/var/log/mongo/mongo.log
rest=true
fork=true

 

The start-up script:

    #! /bin/sh

    CONF=/etc/mongodb.conf

    do_start () {
    echo  “Starting mongo with-> /usr/bin/mongod –config $CONF”
    /usr/bin/mongod –config $CONF
    }

    do_stop () {
    echo “checking if mongo is running”
    PID=$(cat /data/db/mongod.lock)
    if [ -z "$PID" ];
        then
        echo “mongod isn’t running, no need to stop”
        exit
    fi
    echo ” it is”
    echo “Stopping mongo with-> /bin/kill -2 $PID”
    /bin/kill -2 $PID

    }

    case “$1″ in
      start)
        do_start
        ;;
      stop)
        do_stop
        ;;
      *)
        echo “Usage: $0 start|stop” >&2
        exit 3
        ;;
    esac

    <>