24

I installed mongodb following this tutorial here, no errors during the installation but when I try to start the mongod server using this command sudo systemctl start mongodb as the tutorial mentions, i getting this error when i try to check whether it is running using this command sudo systemctl status mongodb.

● mongodb.service - High-performance, schema-free document-oriented 

database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: 
   Active: failed (Result: exit-code) since Rab 2016-06-01 18:04:20 MYT; 4s ago
  Process: 8241 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
 Main PID: 8241 (code=exited, status=14)

Jun 01 18:04:20 yasinya systemd[1]: Started High-performance, schema-free docume
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Main process exited, code=e
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Unit entered failed state.
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Failed with result 'exit-co
lines 1-10/10 (END)

so can anyone tell what is wrong and how I can fix it.

5
  • Check out the answer here, which may help you. Commented Jun 1, 2016 at 10:35
  • ok let me try that thanks Commented Jun 1, 2016 at 10:38
  • 1
    @titi23 i got an error Failed to start mongod.service: Unit mongod.service not found Commented Jun 1, 2016 at 10:43
  • this link may be having the solution. Try searching with the error you are getting. You will get some solution. Commented Jun 1, 2016 at 10:54
  • If you were running a mongodb server and updated the system, chances are it has the “old” lock file: you can try removing it (in Ubuntu: /var/lib/mongodb/mongod.lock) and trying then systemctl start mongodb.service Commented Mar 15, 2018 at 0:52

14 Answers 14

51

Recently i have solved the same issue. I was unable to find the solution on googled, but i get come clues to, how get figure it out. In my case this issue was related to mongodb-27017.sock file.

Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted

So i have changed the permission of /tmp/mongodb-27017.sock file to default mongodb user.

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

After this sudo systemctl status mongodb working fine and mongodb is started.

Sign up to request clarification or add additional context in comments.

3 Comments

same happen with /var/lib/mongodb and /var/log/mongodb
After applying your solution I am getting error - Failed to start mongod.service: Unit mongod.service not found. any idea why?
a shorter one-liner with the same result would be sudo chown mongodb:mongodb /tmp/mongodb-27017.sock.
36

Stumbed on the same issue, just reboot

sudo reboot

5 Comments

saved my day.. !
Wow, this is quite interesting.
This is a persistent problem, the solution works but we can't reboot all the time in production environment...
well done, that was the way to solve the problem
mine on Manjaro was also fixed by rebooting
33

This error returned by MongoDB applications which encounter an unrecoverable error, an uncaught exception or uncaught signal. The system exits without performing a clean shutdown.

I solved the problem by the command:

sudo chown -R mongodb:mongodb /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chmod -R 755 /var/lib/mongodb
sudo chmod -R 755 /var/log/mongodb

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

Then restart service

sudo systemctl restart mongod

Then check your mongodb service

sudo systemctl status mongod

4 Comments

Solved for me! Thanx
Thank goodness. Didn't have *.sock files, but the first 4 commands fixed it! 🙏
This didn't solve the issue for me
Maybe your disk space was full you can check it by df -i , anyway you can check mongodb log file in var/log/mongodb to clearify your server problem
10

I had same use ,

get solve just

sudo reboot

1 Comment

This is the main reason , don't do anything , Just reboot
6

The first thing, you should examine the mongo log. It should tell you what went wrong.

$ tail -n 100 /var/log/mongodb/mongod.log

This command will show last 100 lines of the log file which will point you to the exact problem.

For example, mine wasn't working because i was running a mongo instance using the same port 27017. when i ran another instance, the instance failed to load.

LOG

2018-05-11T19:03:49.102-0400 I CONTROL  [initandlisten] MongoDB starting : pid=1247 port=27017 dbpath=/var/lib/mongodb 64-bit host=dev-hyuen
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] db version v3.2.20
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] git version: a7a144f40b70bfe290906eb33ff2714933544af8
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] modules: none
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] build environment:
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distarch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 127.0.0.1:27017
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten]   addr already in use
2018-05-11T19:03:49.124-0400 E STORAGE  [initandlisten] Failed to set up sockets during startup.
2018-05-11T19:03:49.124-0400 I CONTROL  [initandlisten] dbexit:  rc: 48

1 Comment

this answer cover most of the cases, running tail command on mongo db log file will show exactly what went wrong, and we can debug from there.
6

Step1. sudo systemctl stop mongodb

Step2. sudo systemctl start mongod

Step3. sudo systemctl status mongod

I hope it helps you

Comments

4

Case with me:

  1. I installed mongodb from official site.
  2. Worked fine after installation, even worked with command-line, Robo3T and Compass.
  3. Problems occurred after rebooting once.

So, I checked the status

sudo systemctl status mongod

and got this:-

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2021-02-20 18:11:19 IST; 5s ago
       Docs: https://docs.mongodb.org/manual
    Process: 724411 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
   Main PID: 724411 (code=exited, status=1/FAILURE)

Feb 20 18:11:18 bunty systemd[1]: Started MongoDB Database Server.
Feb 20 18:11:19 bunty mongod[724411]: {"t":{"$date":"2021-02-20T12:41:19.657Z"},"s":"F",  "c":"CONTROL",  "id":>
Feb 20 18:11:19 bunty systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Feb 20 18:11:19 bunty systemd[1]: mongod.service: Failed with result 'exit-code'.

If your case is similar...

How I solved it?

  1. Check if these two directories exists or not: /var/lib/mongodb and /var/log/mongodb.

You can do this with:

test -d /var/lib/mongodb && echo "Directory Exists"
test -d /var/log/mongodb && echo "Directory Exists"
  1. The one which does not exist, make it with mkdir command.
sudo mkdir /var/lib/mongodb # run only if it does not exist
sudo mkdir /var/log/mongodb # run only if it does not exist
  1. Change owners of these directories to mongodb. Do this for both the directories.
sudo chown -R mongodb:mongodb /var/lib/mongodb 
sudo chown -R mongodb:mongodb /var/log/mongodb 
  1. Restart the mongod server.
sudo systemctl restart mongod
  1. Let's check.
sudo systemctl status mongod

If output is something like

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-02-20 18:15:01 IST; 59min ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 734383 (mongod)
     Memory: 166.7M
     CGroup: /system.slice/mongod.service
             └─734383 /usr/bin/mongod --config /etc/mongod.conf

Feb 20 18:15:01 bunty systemd[1]: Started MongoDB Database Server.

you are good to go.

For mongo shell:

mongo

This works for me every time mongod fails, hope it works for you too.

Namaste 🙏

1 Comment

i was facing similar issue and only your solution worked for me
1

I was getting the similar error, in my case mongo couldn't use 27017. I needed to stop whatever was using 27017 port and restart mongo.

Comments

1

because the permission setting

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

if this worked for me after reinstalling mongodb. I have created manually

sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb

and changed owner for both

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

Comments

0

The problem may be related to the lack of space with your /dev/root/ (it was mine).

Check with df -h and see if there enough free space. Otherwise, as explain there, try to free some space by moving the log files to another disk.

sudo /etc/init.d/rsyslog stop
sudo mv /var/log /OTHERDISK/
sudo ln -s /OTHERDISK/log /var/log
sudo /etc/init.d/rsyslog start

Hope it could help as it helps me

Comments

0

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

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

Comments

0

In my case, increasing ulimit value for number of open files, solved my problem.

Like in the MongoDB docs note, if you execute ulimit -n command and the result is lower than 64000. Just execute this command: ulimit -n 128000. By the way 128000 is not a specific number. I made it up.

Comments

0

I'm using Ubuntu 20.04.5 LTS.

After trying all of the above that didn't work.

sudo apt-get install --reinstall mongodb

Reinstalling it solved the problem for me.

Comments

-1

In my case the system was not able to to find mongod.service Running the following command will fixed it

sudo systemct1 enable mongod

then restart the database by

sudo service mongod restart

1 Comment

sudo systemctl enable mongod

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.