I'm having some trouble with intentionally removing a secondary from a replica set. I'm trying to simulate unexpected shutdown.

My replica set consists of one primary and 2 secondaries. When I shut down the mongo instance on one of the secondaries and try to restart the service it fails with the message from the log which states:

Tue Dec 24 12:20:08.882 [initandlisten] couldn't open /var/lib/mongo/maars.ns errno:13 Permission denied

Simple chown -R mongod /var/lib/mongo solves the problem, but this shouldn't happend. Am I doing something wrong?

Ask for more info if you need something.


1 Answer 1


Usually the cause for this is that you are restart the mongod process as the root user (using sudo, or perhaps invoking directly as root) or some other user besides the appropriate MongoDB user (in your case mongod). That is then screwing up the permissions in your data folder and giving you the error you are seeing.

If you examine how you are starting/stopping the process and correct it to only start with the correct user (or use the service commands instead) then this problem should stop happening.

  • I'll mark it as answer, thank you. I guess this is by design? Same thing will happen when one of my secondaries loses power source? Is manual intervention needed anyway? Huh, lotta questions :) Thank you Adam.
    – ivica
    Dec 31, 2013 at 20:21
  • 1
    Manually starting the mongod as root (or another alternate user) and incorrectly setting permissions is not by design, it's not something you are supposed to do. Generally the mongod process should be started with the service command or from the init script (depending on your distro) so that it starts as the correct user. If you know what you are doing you can start it as the correct user manually (using su etc.) but this is basically true of most Linux services, not something unique to MongoDB.
    – Adam C
    Jan 1, 2014 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.