Ok, this was about to drive me crazy, and it seems like a lot of people have run into the same problem but sometimes my Mongo installation dies on me with an error like this:
10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Yeah, I didn’t get that either. The actual error is not hard to understand, there’s some kind of permission needed on the /data/db-directory. But why? And how to fix it?
Why… well in my case it was when I had to shut down a running VirtualBox image by just closing the image window, the equivalent of pulling the cord of a running computer. So probably Mongo didn’t have time to clean up after itself…
Fix it… yeah, there’s a big number of posts on StackOverflow, take your pick. This tip worked for me:
- Check the rights to the /data/db directory by doing “ls -ld /data/db”. It should be “drwxr-xr-x” if that says something to you. Not to me
- Change the access rights, if needed by doing “sudo chmod 0755 /data/db”
- And for the user running mongo (in my case myself) “sudo chown -R $USER /data/db”
- Run “mongod” to start Mongo and verify that it works
Aaaand after that… It still didn’t work. I had to reinstall the whole thing. Here’s a description on how to clean and reinstall Mongo. And here’s a description on how to edit /etc/apt/sources.list
I’m sure this will help me again when I need it!