MongoDB Service Will Not Start After Initial Setup

Pori picture Pori · Apr 15, 2014 · Viewed 39.4k times · Source

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

Answer

Wayne picture Wayne · Jun 11, 2014

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)