Attempted to create a lock file on a read-only directory

Hello, I have installed Vagrant and VirtualBox as guided but now I’m stuck at the moment where I’ve been asked to start mongod with a config file. The error is logged:

Screenshot 2019-12-24 at 19.06.27

So when I go check logs I see this:

Screenshot 2019-12-24 at 19.06.59

And here are my permissions for the stuff inside /data/ directory:

Screenshot 2019-12-24 at 19.05.38

I’ve tried to:

  • change the ownership to mongodb;
  • execute mongod with sudo;
  • execute chmod +w on /db/ directory;

Nothing seems to work so far. But the server starts up perfectly fine if I type the options right in the shell instead of using the configuration file. Please help me to solve this the right way. Changing chmod to 777 of the db directory is not an option and is wrong approach, please don’t suggest me to do this.

Welcome @Boris_03771,

No one here would suggest that anyway :wink:

Not recommended in any circumstance.

Let’s see a screenshot of your config file. Be prepared to delete it as well because it’s against forum guidelines to keep lab solutions on the forum.

Also show the output of ps -ef | grep [m]ongo

Thank you for your reply. Here is my config file, but I even tried empty config file and the outcome is the same:

removed

Here is output of the command that you have asked for:

Screenshot 2019-12-25 at 00.34.03

Let’s make a few slight tweaks:

  1. Add the logAppend option to your config file… have a look at the Config File documentation for usage.
  2. Delete the /data/db and /data/log sub-directories completely and mkdir them again. Do not use sudo either.
  3. Change this:
    image
    to this:
    bindIp: "127.0.0.1,192.168.103.100"
    I.e. no spaces and using the correct IP related to the lab requirements

Feel free to remove the config file snapshot from your last post.

1 Like

It’s worked! Thank you very much. The #2 tweak did the thing.

Yes that was the main one. The others were mainly recommendations. Good job! :+1:

I’ve just figured out that the problem reappears when I terminate mongod with CTRL + Z command (it was running w/o fork being set to true so I had the mongod in the shell tab opened). But if I connect to the mongo and then type

use admin
db.shutdownServer()

instead of using ctrl-z then the server is capable to start up again w/o the problem mentioned above. I wonder what should I do if I had electricity cut off or something so didn’t manage to shutdown server properly. Then I would have the exact same problem but remain unable to remove the db directory simply because the data would be lost I assume?

This is the problem. This is a signal that sends mongod to the background at which point there’s still a lock on the file. You need to be using Ctrl+C, or better still shutdown.

1 Like

Hi @Boris_03771,

In addition to @007_jb,

The “ctrl+zdoesn’t kill the process, it merely suspends the process and pushes it into the background. You can resume it again by running the fg command.

Whereas, the ctrl+c command kills the process.

However, the safest and the recommended way of shutting down the mongod server is db.shutdownServer().

Hope it helps!

If you have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

1 Like