Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 23037  / 3 Years ago, fri, september 10, 2021, 8:32:45

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

More From » 12.04

 Answers
1

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/

[#36189] Sunday, September 12, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cklaceowne

Total Points: 228
Total Questions: 102
Total Answers: 111

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;