8

After I updated to 12.04 a month or two ago I installed MongoDB via APT. Since that time it has worked well. I made no changes to the config or anything - it just worked out of the box.

Today it didn't start, when I logged on I suddenly had a "couldn't connect to any servers in the list" error in my application and I checked and mongod wasn't running.

ls -al /var/lib/mongodb

Shows no *.lock files.

$ /etc/init.d/mongodb start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongodb start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongodb
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.89" (uid=1000 pid=4284 comm="start mongodb ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

Then I tried sudo mongod --repair

Mon Aug 13 12:16:48 [initandlisten] MongoDB starting : pid=4350 port=27017 dbpath=/data/db/ 64-bit host=computer-localhost
Mon Aug 13 12:16:48 [initandlisten] db version v2.0.4, pdfile version 4.5
Mon Aug 13 12:16:48 [initandlisten] git version: nogitversion
Mon Aug 13 12:16:48 [initandlisten] build info: Linux yellow 2.6.24-29-server #1 SMP Tue Oct 11 15:57:27 UTC 2011 x86_64 BOOST_LIB_VERSION=1_46_1
Mon Aug 13 12:16:48 [initandlisten] options: { repair: true }
Mon Aug 13 12:16:48 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Mon Aug 13 12:16:48 dbexit: 
Mon Aug 13 12:16:48 [initandlisten] shutdown: going to close listening sockets...
Mon Aug 13 12:16:48 [initandlisten] shutdown: going to flush diaglog...
Mon Aug 13 12:16:48 [initandlisten] shutdown: going to close sockets...
Mon Aug 13 12:16:48 [initandlisten] shutdown: waiting for fs preallocator...
Mon Aug 13 12:16:48 [initandlisten] shutdown: lock for final commit...
Mon Aug 13 12:16:48 [initandlisten] shutdown: final commit...
Mon Aug 13 12:16:48 [initandlisten] shutdown: closing all files...
Mon Aug 13 12:16:48 [initandlisten] closeAllFiles() finished
Mon Aug 13 12:16:48 dbexit: really exiting now

Any idea what is wrong?

Update

So I tried sudo service mongodb start and it finally started (I tried this several times before)

mongodb start/running, process 4376

4 Answers 4

13

Diagnosis

The first thing to do is to check the MongoDB log files to see why the service didn't start. Run:

tail -f /var/log/mongodb/mongodb.log

in one terminal window and then run:

sudo service mongodb restart

in another. The log file should show MongoDB attempting to start and report an error message if it fails.

Repair

If the logs indicate that you need to repair your database, there are two points to bear in mind:

  1. By default, mongod expects the database files to be in /data/db/, but the Ubuntu packages configure it to look in /var/lib/mongodb/. So if you run mongod directly rather than using the upstart scripts, you need to tell it where your database files are by adding a --dbpath argument.
  2. When running mongod using upstart, it will run as the mongodb user which is the user that owns the database files. If you run mongod using sudo without specifying a user then you will end up with database files owned by root. So you need to add a -u argument to sudo.

If your database files are currently owned by root you will need to change their ownership back to mongodb before MongoDB can use them again:

sudo chown -R mongodb:mongodb /var/lib/mongodb/

TL;DR

To run a repair on MongoDB when using the packaged distribution, you need to run:

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

I also had the same problem, and solved it. When I tried to start mongodb with sudo it showed the process was already running (mongodb start/running, process xxxx). But I cannot access the running instance through the shell. It showed connection failed.

The Solution

So I deleted the lock file:

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

Then I restarted the service:

sudo service mongodb start

Then Mongo worked on my machine again!

0
0

I also had similar problem of starting mongod.exe in my machine (Windows installation). The was a .lock file in C:\data\db which was causing the problem. I deleted that file and the issue got resolved.

0

Had a similar problem, cause was kinda stupid; I was out of disk space.

Checking the logs at /var/log/mongodb/mongod.log I spotted the following line:

2015-04-13T10:56:37.132+0200 [initandlisten] ERROR: Insufficient free space for journal files

Hoping this saves somebody half an hour of their life.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .