1

From the MongoDB manual:

To start the server as a daemon listening on port 5586 and sending all output to mongodb.log, we can do:

mongod --port 5586 --fork --logpath mongodb.log

What is the benefit to run an application as a daemon and when I should do so?

2 Answers 2

1

If you run MongoDB not forked (also known as a daemon), the instant you close your shell or SSH window, MongoDB will also be shutdown.

The reason why you want to fork it into the background (as a daemon) is so that you are able to continuously run MongoDB separate from your shell, that way it will run without interruption (unless you kill it yourself, or shutdown your computer).

2
  • Is it same as if I run mongod --port 5586 --logpath mongodb.log &? In other word, I use & to force the application run into the background?
    – q0987
    Oct 31, 2011 at 20:10
  • Not entirely, if you use &, it will only be useful to your "session". If it is remote, and you kill your Terminal window, it will also kill Mongo as you are not logged in anymore to keep your background processes in place. If you are using a desktop interface, logging out will also kill this process.
    – Steven Lu
    Oct 31, 2011 at 20:14
1

When you run an application as a daemon, it stays running after you log off of the computer.

This is useful for hosting services from your computer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .