Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Service Will Not Start After Initial Setup

I am running Fedora 20 and installed MongoDB per the Red Hat installation guide on the official documentation. I was able to run the mongod daemon as a service without error the very first time but when I shut down my machine and came back, the service refused to start due to some failure.

In my log, listed after the successful run, I see this:

***** SERVER RESTARTED *****
ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory

If I try starting mongod or running mongod --repair manually, I get this message in a start up failure:

ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.

This is odd considering that in my config file in /etc/mongod.conf, the settings for the database path are as follows:

dbpath=/var/lib/mongo

Finally, if I run this command:

mongod --dbpath /var/lib/mongo

The daemon starts up just fine. However, I am unable to replicate that error free behavior for starting a service.

Can anyone tell me what exactly is wrong and how I can begin running mongod as a service?

EDIT

I get this message if I run mongod --config /etc/mongod.conf:

about to fork child process, waiting until server is ready for connections. forked process: 2702 ERROR: child process failed, exited with error number 1

The /var/run/mongodb directory did not exist, so I created and assigned it to the mongod user. That did not make much of a difference, unfortunately.

My /var/log/mongodb/mongod.log shows this message:

[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongo/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

like image 884
Pori Avatar asked Apr 15 '14 14:04

Pori


People also ask

Why MongoDB server is not starting?

We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with –config /etc/mongodb.


Video Answer


2 Answers

What worked for me on Fedora 20: we need to create the temp dir on every boot, and that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf and put one line in it:

d /var/run/mongodb 0755 mongod mongod

That seems to handle it on restarts; if you don't want to restart right away, you can execute that with:

sudo systemd-tmpfiles --create mongodb.conf

(See the man pages for systemd-tmpfiles)

like image 187
Wayne Avatar answered Nov 15 '22 21:11

Wayne


I have the same problem, I solved it temporarily, disabling SELinux, rebooted the machine, eliminated mongod.lock:

#rm /var/lib/mongo/mongod.lock

By creating the file /var/run/mongodb/mongo.pid (as mentioned in the configuration file /etc/mongod.conf):

#mkdir /var/run/mongodb
#touch /var/run/mongodb/mongod.pid

and giving 777 permissions:

#chmod 777 /var/run/mongodb/mongod.pid 

and starting mongo:

#service mongod start

But the problem persists after restarting the machine. The folder and file disappear.

like image 39
Deoxyseia Avatar answered Nov 15 '22 20:11

Deoxyseia