14
votes

I have installed mongodb and when i typing the following command i am getting these messages

root@amila:~# service mongodb status    
mongodb stop/waiting
root@amila:~# service mongodb restart    
restart: Unknown instance:     
root@amila:~# service mongodb stop    
stop: Unknown instance: 

I want to restart mongodb.but unable to restart.

EDIT: here is the /etc/mongodb.conf

dbpath=/var/lib/mongodb logpath=/var/log/mongodb/mongodb.log

logappend=true

bind_ip = 127.0.0.1
auth = true

8
What's the output of service mongodb start ?Emil Vikström
can you paste the contents of your /etc/mongodb.conf file?ghstcode
service mongodb start mongodb start/running, process 9012Amila
belongs on serverfault.com Q&A for system administrators and desktop support professionalsMchl
Have you been able to solve this? I have the same problem and the answers here did not solve my problem. Also removing the mongo.lock file as suggested in other posts does not help.SeeDoubleYou

8 Answers

11
votes

Given the output of the start command, this is starting correctly. When you are running status, it seems to have been stopped. You need to look into the log file:

/var/log/mongodb/mongodb.log

That will tell you why the mongod is stopping. There are a couple of likely causes, but without seeing that output it will be hard to answer definitively. My general recommendations:

  1. Do not use bind_ip - it is a bad idea in general Update (2016): Removing this because the issues with bind_ip that caused me to write this back in 2012 have been fixed, and it is even on by default in official packages now. Worth trying without the setting as a troubleshooting step, but not a bad idea to use it in general.
  2. Check for something else running on port 27017
  3. Specify the port explicitly in the mongodb.conf file, even if you want to use the default

Finally, take a look at this answer for how to fix file permissions, just in case that is a problem (usually caused by running as root at some point):

mongodb crashes after unexpected shutdown

9
votes

Sorry if you consider this "SO archeology".

I don't know if this is the same issue, but I'm facing something similiar right now. End of my log:

Mon Nov 19 10:25:37 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Mon Nov 19 10:25:37 dbexit: 
Mon Nov 19 10:25:37 [initandlisten] shutdown: going to close listening sockets...
Mon Nov 19 10:25:37 [initandlisten] shutdown: going to flush diaglog...
Mon Nov 19 10:25:37 [initandlisten] shutdown: going to close sockets...
Mon Nov 19 10:25:37 [initandlisten] shutdown: waiting for fs preallocator...
Mon Nov 19 10:25:37 [initandlisten] shutdown: lock for final commit...
Mon Nov 19 10:25:37 [initandlisten] shutdown: final commit...
Mon Nov 19 10:25:37 [initandlisten] shutdown: closing all files...
Mon Nov 19 10:25:37 [initandlisten] closeAllFiles() finished
Mon Nov 19 10:25:37 dbexit: really exiting now

So I think the lock file is not closed properly (for example when shutting down). You should use

mongod --repair

But it didn't work for me, so I just removed /var/lib/mongodb/mongod.lock and then started the server. This is not the secure way, and there is possibility, that data in your database is corrupt if you do so.

7
votes

Sorry to rehash this thread, but I'm putting this here because I ran into the exact same issue and this worked.

taken from here:

http://pastebin.com/6hP42r69

sudo -u mongodb mongod --repair -dbpath /var/lib/mongodb

I'm running linux mint 15 and current mongodb build.

6
votes

I had the same problem and I solved running just:

$ service mongod restart

2
votes

I solved this manually deleting .lock file like that

sudo rm -i /var/lib/mongodb/mongod.lock

then restart

1
votes

Looks like Mongo is unable to start for some reason. Apart from the suggestions already provided by Adam.

  • Check to see if you have write permissions to the data directory.
  • Check to see if you have write permissions to the /var/log directory.
  • Is mongod running as root or as another user? Check the init script for mongodb to see what user is mongod running as.
1
votes

One of the possible cases might be mongod.lock(which was causing my problem).

Open your log file at

/var/log/mongodb/mongod.log

See if you have any exception because of mongod.lock file. Copy it's location and remove it

sudo rm /var/lib/mongodb/mongod.lock

Then run

sudo service mongod restart

To check if everything is fine now.

sudo service mongod status

Expected output will be mongod start/running

1
votes

Sometimes the problems can be caused by not having enough free storage for journaling to continue smoothly.

Did a tail -100 /var/log/mongodb/mongod.log and found this error:

exception in initAndListen: 15926 Insufficient free space for journals, terminating Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles`

Resolved it by putting smallfiles=true in my MongoDB config file /etc/mongod.conf.

Then sudo rm /var/lib/mongodb/mongod.lock

And then restarting the MongoDB instance using service mongod start

Hope this help.