MongoDB Service Will Not Start After Initial Setup

I've spent a while looking into this, and it appears as if the pid folder and file permissions don't work with the default daemon.

The simplest solution I've come across is disable the pid file by just putting a # in front of the line in the config file.

vi /etc/mongod.conf

find the line that says pidfilepath=/var/run/mongodb/mongod.pid and change it accordingly.

# pidfilepath=/var/run/mongodb/mongod.pid

For information on what commenting it out does check here. http://docs.mongodb.org/manual/reference/configuration-options/#processManagement.pidFilePath


If you’re starting mongod as a service using:

sudo service mongod start

Make sure the directories defined for logpath, dbpath, and pidfilepath in your mongod.conf exist and are owned by mongod:mongod.


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.


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)