I have setup a Mongodb replica set with 1 secondary node. When i execute on secondary

sudo mongod --replSet rs0 --dbpath /data --port 27017 --oplogSize 700

The primary and secondary nodes are linked and it works perfectly but the connection logs are running in open terminal. I would like to run the above task as background job. The option of -d doesn't seem to work here.

migrated from stackoverflow.com Dec 23 '13 at 14:16

This question came from our site for professional and enthusiast programmers.

  • 1
    You need --fork and also --logpath so logs can go somewhere. – Asya Kamsky Dec 23 '13 at 6:45
  • Btw, mongod --help lists and describes all available options. – Asya Kamsky Dec 23 '13 at 6:59

You can make mongod run in the background with --fork and you will also need to direct your logfiles somewhere with --logpath when you do so. Before you go about doing all of that though, you should not run mongod as root (which you are doing by using sudo in the command you pasted).

Run it as a regular user, if you have installed MongoDB from one of the packages then you should have the mongod or mongodb user on the systems. Make sure the dbpath (/data) has the appropriate permissions (as well as wherever you put your logs) and you should have no problems. For reference, you would change the permissions on /data as follows (assuming a user and group of mongod):

sudo chown -R mongod:mongod /data

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.