6
votes

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.

8
There should be a monod.lock file in the data/db folder. Please delete it and try restarting again.Prasad Kharkar
@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.M.J
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
@PrasadKharkar: Thanks PrasadM.J

8 Answers

9
votes

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. :-)

4
votes

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!

2
votes

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.

2
votes

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!

1
votes

I removed the mongodb lock file-

sudo /data/db/mongod.lock

Then restarted the mongodb

sudo service mongod restart

This solved the issue.

0
votes

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.

0
votes
  • 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.

-1
votes

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