Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb is not starting in ubuntu

Tags:

mongodb

I am having a weird problem with mongodb after installation it is ending with a message

invoke-rc.d: unknown initscript, /etc/init.d/mongodb not found.
dpkg: error processing mongodb-10gen (--configure):

What is wrong here I followed the steps given here: http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

like image 998
Hirak Sarkar Avatar asked May 24 '12 07:05

Hirak Sarkar


People also ask

Why MongoDB is not opening?

We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with –config /etc/mongodb.

How do I start MongoDB in terminal?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.

Why is my MongoDB not connecting?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.


2 Answers

The issue is that you are trying to install a version packaged for Upstart init services, but Debian Squeeze still uses SysV init by default.

There is a note on this in the install docs: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian-or-ubuntu-linux/#installing-mongodb

If you are using Debian or Ubuntu that uses SysV style init process, use the following line:

deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
like image 75
kratos Avatar answered Oct 24 '22 20:10

kratos


This means that you need to create mongodb start script in /etc/init.d/

Try this script

#!/bin/bash
#
# mongodb     Startup script for the mongodb server
#
# chkconfig: - 64 36
# description: MongoDB Database Server
#
# processname: mongodb
#

# Source function library
. /lib/lsb/init-functions 

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

prog="mongod"
mongod="/usr/local/mongodb/bin/mongod"
RETVAL=0

start() {
    echo -n $"Starting $prog: "
    daemon $mongod "--fork --logpath /var/log/mongodb.log --logappend 2>&1 >>/var/log/mongodb.log"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

reload() {
    echo -n $"Reloading $prog: "
    killproc $prog -HUP
    RETVAL=$?
    echo
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
        fi
        ;;
    reload)
        reload
        ;;
    status)
        status $mongod
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
        RETVAL=1
esac

exit $RETVAL

after type in terminal:

sudo chmod +x /etc/init.d/mongodb
sudo /etc/init.d/mongodb start
ps -A | grep mongod
like image 22
Dmitry Zagorulkin Avatar answered Oct 24 '22 19:10

Dmitry Zagorulkin