mongod fork vs nohup

I'm currently writing process management software. One package we use is mongo.

Is there any difference between launching mongo with

mongod --fork --logpath=/my/path/mongo.log --logappend

and

nohup mongod >> /my/path/mongo.log 2>&1 < /dev/null &

?

My first thought was that --fork could spawn more processes and/or threads, and I was suggested that --fork could be useful for changing the effective user (downgrading privileges). But we run all under the same user (process manager and mongod), so is there any other difference?

Thank you


The difference is that with

mongod --fork --logpath=/my/path/mongo.log

Mongo itself forks the process so it can run as a deamon. This is the intended way because mongo might probably do something before forking the new process.

With

nohup mongod >> /my/path/mongo.log 2>&1 < /dev/null &

Mongo does not know it is forked.

I'd say it is always better to let server software do the forking so it can make optimizations. NoHUP is just for software that does not have a forking option.


I agree generally with Christopher P's answer (and voted it up), but to speak a little more about the logging option here. An initial scan of the examples you have given would suggest that you would end up with better logging options with the nohup version that the --fork version. If instead you started with:

mongod --fork --logpath=/my/path/mongo.log --logappend

Then, you would have a closer match. It also gives you the option of rotating the log files pretty easily (via a signal or a command):

http://www.mongodb.org/display/DOCS/Logging#Logging-Rotatingthelogfiles

Otherwise you would need to manage it all yourself and the process is going to think it is logging to stdout instead of to a file.

Not exactly what you were asking, but some more evidence in favor of --fork.