75

So im trying to setup Mongodb on Ubuntu 16.04 but im running into trouble.

when running :

sudo systemctl status mongodb

I get the following:

 mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2016-09-10 14:02:22 CEST; 14s ago
     Docs: https://docs.mongodb.org/manual
  Process: 8724 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=14)
 Main PID: 8724 (code=exited, status=14)

According to the mongo-docs, status=14 is:

"Returned by MongoDB applications which encounter an unrecoverable error, an uncaught exception or uncaught signal. The system exits without performing a clean shut down."

I doesnt really point me in any particular direction.

My /etc/systemd/system/mongodb.service looks like this:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

Any thought on what may be the cause of this?

Thank you

2
  • What does the MongoDB log say (usually in /var/log)?
    – Adam C
    Sep 12, 2016 at 22:44
  • Hey Adam, sorry for not getting back here. I did solve the problem by reinstalling mongo. Thank you though. Sep 17, 2016 at 14:04

10 Answers 10

180

After googling around for a while. I found that that is because the permission settings on /var/lib/mongodb and /tmp/mongodb-27017.lock are wrong. You will have to change the owner to monogdb user

sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock

then

sudo service mongod restart
11
  • 18
    +1 for finding the undocumented chown mongodb:mongodb /tmp/mongodb-27017.sock... May 24, 2019 at 5:53
  • 1
    +1 for chown -R mongodb:mongodb /var/lib/mongodb
    – luongnv89
    Aug 2, 2019 at 15:20
  • 2
    I have lost yesterday just because of it. You should have good googling skills :) Aug 3, 2019 at 8:14
  • Hi I did change the permissions as above but still I'm unable to create a replica set which exits with error 14.Any ideas? Here is the link that I'm using mongodb.com/blog/post/mongodb-change-streams-with-python Jan 20, 2020 at 5:49
  • 1
    This resolved my issue.. Thanks a lot :) Jun 2, 2020 at 7:42
10

By using this my error was gone:

  1. Go to the TMP directory: cd /tmp
  2. Check if you have the mongodb sock file: ls *.sock
  3. Change the user:group permission: chown mongodb:mongodb <YOUR_SOCK>
  4. Start MongoDB: sudo service mongod start
  5. Check the MongoDB status: sudo service mongod status
2
  • in tmp i have no .sock files. What possibly can go wrong? Aug 14, 2020 at 10:22
  • when i try to do it, it says operation not permitted, any ideas?
    – Yanis
    Dec 17, 2021 at 19:37
7

deleting the mongod sock file solved the issue for me sudo rm -rf /tmp/mongodb-27017.sock then start again sudo systemctl start mongod

5
  1. Check for both mentioned directories If they don't exist, use the following commands:
sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
  1. Clear the socket with the following command:
chown mongodb:mongodb /tmp/mongodb-27017.sock
  1. Restart and check the status of the service:
sudo service mongod restart
1
  • Just a small correction in response to your valuable answer in step 2 we need to add sudo before chown....... Mar 14, 2021 at 9:13
2

i tried this and it worked :

sudo nano /etc/mongod.conf

comment the "bind ip" line.

sudo mongod --auth --port 27017 --dbpath /data/db

then i ran

sudo service mongod restart
1

for beginners only if you are trying the following and getting errors :

  sudo chown -R mongodb:mongodb /var/lib/mongodb
  sudo chown mongodb:mongodb /tmp/mongodb-27017.sock 
  sudo service mongod restart

then try checking the status

  sudo systemctl status mongod

it will show active ..

1

I also got status 14 at some point, but it was not because of my .lock files.

Looks like everything in your dbPath (in my case /data/mongodb) should belong to mongodb. In my case, two files and files in the journal folder were owned by root, possibly because I have run the mongod command with sudo instead of the mongodb user (as configured in mongod.service).

sudo chown mongodb:mongodb /data/mongodb/ -R

In order to find my problem, it helped to set the verbosity to 5 in /etc/mongod.conf:

systemLog:
  verbosity: 5

and run tail /var/log/mongodb/mongodb.log -n 100 after sudo systemctl start mongod

For this to work, mongod.conf needs to be loaded by mongod. mongod.service does that with the --config parameter.

Make sure to remove the high verbosity when your mongodb works again, because that logfile can grow very large.

0

My /var/lib/mongodb was corrupt, rming it and reinstalling mongo worked.

0

This error occurred for me just because the disk space was full. And solved after deleting some unused files.

0

In my case, it was because of an incomplete repair operation, in which case I had to run mongod --repair --dbpath /var/lib/mongodb.

Not the answer you're looking for? Browse other questions tagged or ask your own question.