mongodb Unable to create/open lock file
I installed mongodb:
sudo apt-get install mongodbTried to run it:
mongodRuns into this error:
Mon Aug 21 20:46:44 [initandlisten] exception in initAndListen: 10309 Unable to create/open
lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminatingBut the access rights must be fixed by now:
makan@blah:~$ls -hal /data/db/
total 8.0K
drwxr-xr-x 2 mongodb mongodb 4.0K Aug 21 19:56 .
drwxr-xr-x 3 mongodb mongodb 4.0K Aug 21 19:56 ..and:
makan@blah:~$ls -hal /data/
drwxr-xr-x 2 mongodb mongodb 4.0K Aug 21 19:56 dbSo why can't mongodb open/create the lock file?
41 Answer
From the question description it appears you are running mongod from your own account (user: makan).
Your invocation of mongod without specifying a configuration file or --dbpath would require this user to have read/write permissions for the default dbpath directory (/data/db). Since /data/db is only writable by user mongodb, a permission error is expected when mongod tries to write a file running with the permissions of makan:
lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
The usual way to start/stop mongod is using the service definition, which runs as the user and group mongodb via sudo service mongod start.
The service uses a configuration file (/etc/mongod.conf) and a data directory (/var/lib/mongodb) which should already have the correct permissions after installation.