6

I have installed MongoDB 3.0.6 in Ubuntu 15.04 using the following commands.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

In the end in the installation process I got this:

Job for mongod.service failed. See "systemctl status mongod.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mongod, action "start" failed.
dpkg: error processing package mongodb-org-server (--configure):
subprocess installed post-installation script returned error exit status 1
Setting up mongodb-org-mongos (3.0.6) ...
Setting up mongodb-org-tools (3.0.6) ...
dpkg: dependency problems prevent configuration of mongodb-org:
mongodb-org depends on mongodb-org-server; however:
Package mongodb-org-server is not configured yet.

dpkg: error processing package mongodb-org (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for systemd (219-7ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
mongodb-org-server
mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)

After that when I start the server using the below command I get an error and the server is not started.

sudo service mongod start

And the error is

Job for mongod.service failed. See "systemctl status mongod.service" and "journalctl -xe" for details.

Now when I run:

sudo systemctl status mongod.service

I get the following:

mongod.service - LSB: An object/document-oriented database
Loaded: loaded (/etc/init.d/mongod)
Active: failed (Result: exit-code) since Thu 2015-10-08 13:46:08 IST; 22s ago
Docs: man:systemd-sysv-generator(8)
Process: 6604 ExecStart=/etc/init.d/mongod start (code=exited, status=1/FAILURE)

Oct 08 13:46:07 gariya-GA-A55M systemd[1]: Starting LSB: An   object/document-oriented database...
Oct 08 13:46:07 gariya-GA-A55M mongod[6604]: * Starting database mongod
Oct 08 13:46:08 gariya-GA-A55M mongod[6604]: ...fail!
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: mongod.service: control process exited, code=exited status=1
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: Failed to start LSB: An  object/document-oriented database.
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: Unit mongod.service entered failed state.
Oct 08 13:46:08 gariya-GA-A55M systemd[1]: mongod.service failed.

Someone please help, I am new to Ubuntu and MongoDB and I am not getting what is the problem.

Mukesh Joshi
  • 2,784
  • 4
  • 24
  • 34
  • There should be a monod.lock file in the data/db folder. Please delete it and try restarting again. – Prasad Kharkar Oct 08 '15 at 08:46
  • @PrasadKharkar : Where is this data/db folder. I created it in Home as suggested by TMichel below but nothing happens. I still get the above error. – Mukesh Joshi Oct 08 '15 at 09:36
  • Hi Mukesh, usually while starting mongodb, you need to specifiy a path where database will be stored. From what I see, you have installed mongodb using sudo apt-get so maybe you do not have to specify it and by default some location has been selected. Please locate the "mongodb.lock" file in your system from where you can see. Otherwise, you can check mongo.conf file to check where the "data/db" folder is. – Prasad Kharkar Oct 08 '15 at 09:52
  • @PrasadKharkar: Thanks Prasad – Mukesh Joshi Jan 23 '16 at 08:50

8 Answers8

12

There is a log file: /var/log/mongodb/mongod.log

In the log I've found the following:

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

Most probably this was from previous MongoDB version. I deleted the file (rm -rf /tmp/mongodb-27017.sock) and finished the installation:

apt-get install mongodb-org

Now it works. :-)

pwojnowski
  • 382
  • 4
  • 8
  • The most likely cause for this was that the mongod process was at some point started by the root user - http://stackoverflow.com/questions/29813648/failed-to-unlink-socket-file-error-in-mongodb-3-0 – naXa stands with Ukraine Apr 06 '16 at 19:05
  • In my case, it was unable to remove the socket file, so I solved it with sudo rm /tmp/mongodb-27017.sock – Eugene Mar 05 '21 at 16:01
4

Recently i ended up with same issue and i tried all the possible solutions explained up here. But it didn't worked out for me. I was getting the below error.

# sudo service mongod restart
Restarting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details. [FAILED]

Eventually i figured out the solution which worked for me. I went to /run/mongodb folder and deleted the file called mongod.pid. Then tried to restart the mongo using # sudo service mongod restart and it's worked!

Prasad G K
  • 136
  • 1
  • 7
2

My log said:

[initandlisten] Found an invalid index { v: 2, key: { version: 1 }, name:   "incompatible_with_version_32", ns: "admin.system.version"

so:

 $cd /var/lib
 $sudo rm -rf ./mongodb
 $sudo mkdir mongodb
 $sudo chown -R mongodb.mongodb mongodb/
 $sudo service mongod restart

and then all worked fine.

aarkerio
  • 2,183
  • 2
  • 20
  • 34
2

sudo nano /etc/systemd/system/mongodb.service

[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

sudo systemctl start mongodb

sudo systemctl status mongodb

sudo systemctl enable mongodb

Is job!

0
  • Make sure that the /data/db directory exists
  • Make sure your user have write privileges in that directory:

    $ sudo chown id -u /data/db

  • Execute mongod

If you still have problems and if the file /data/db/mongod.lock exists, remove it and execute mongod --repair.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
TMichel
  • 4,336
  • 9
  • 44
  • 67
  • 1
    Didn't work for me ... anything else that can be done? – samvv Mar 14 '16 at 08:19
  • I was having the same issue, after some searching I got that when I executed the command to restart mongodb I changed the permissions of the db folder . – Satpal Tanan Apr 27 '16 at 17:21
0

The first thing you should check is a mongodb log file located at /var/log/mongodb/mongod.log

Look for the line with status E containing words like 'failed', 'fatal', etc.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
0

I removed the mongodb lock file-

sudo /data/db/mongod.lock

Then restarted the mongodb

sudo service mongod restart

This solved the issue.

-1

I was having the same issue, after searching I got the answer that, when I executed

sudo service mongod restart

I changed the permissions from user mongodb to root of the database folder, so the service was not able to read the data. So to solve I just reverted the permissions back to the user mongodb

sudo chown -R mongodb:mongodb /path-to-db-folder
sudo service mongod restart
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Satpal Tanan
  • 1,108
  • 7
  • 17