Ubuntu – Unable to create lock file when starting mongod via upstart

lockmongodbpermissionsservices

I'm trying to set up my mongodb upstart script to work as an arbiter, but I'm having permission problems when trying to create the lock file in the data directory:

Tue Apr  1 17:11:01 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/tmp/arb", journal: "true", logappe
nd: "true", logpath: "/var/log/mongodb/mongodb-arbiter.log", port: 27017, replSet: "rs1" }
Tue Apr  1 17:11:01 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /tmp/arb/mongod.l
ock errno:13 Permission denied Is a mongod instance already running?, terminating

There definitely is no lock file present and there definitely is no other mongod process running (ps -A | grep mongod will return nothing).

Also when I try to start the mongod process

mongod --fork --port 27017 --dbpath /data/arb --replSet rs1 --logpath /var/log/mongodb.log

this will also throw the same error when not sudoed.

How can I setup the right permissions for the upstart script to write data in /data/arb ?

Best Answer

You need to have the permissions on that folder (and everything under it) such that the mongodb user can write to it. The reason it is working with sudo is because the root user has those permissions regardless of the owner/group. In fact, that may be the root cause here - when you run the mongod process with sudo it will create the files with root:root ownership which the normal mongodb user cannot access.

The user:group for MongoDB on Ubuntu is usually mongodb:mongodb, hence just do the following:

cd /tmp/arb
sudo chown -R mongodb:mongodb .

Since you are running an arbiter here I would also recommend the following options in your config file (note: not for use on a regular data bearing node - arbiter only):

These settings will minimize the footprint of the arbiter on the host.

Related Question