Manish Patel
Manish Patel

Reputation: 4491

First startup of mongod fires up multiple mongod processes

Given a clean mongo data directory, I run a start up script like this (I realise I could use service, but that's a different issue and I'm using this script as a workaround):

>$ cat startMongo.sh
nohup sudo mongod --rest --fork --config /etc/mongod.conf > logs/mongo.log 2>&1 &

The problem is this somehow start lots of processes:

>$ ps -efw | grep mongo
root      7038     1  0 21:29 pts/0    00:00:00 sudo mongod --rest --fork --config /etc/mongod.conf
root      7039  7038  0 21:29 pts/0    00:00:00 mongod --rest --fork --config /etc/mongod.conf
root      7040  7039  0 21:29 ?        00:00:00 mongod --rest --fork --config /etc/mongod.conf
root      7041  7040 10 21:29 ?        00:00:01 mongod --rest --fork --config /etc/mongod.conf

I think this is happening whilst Mongo does some preallocations, which I can see in the log file. After a while, the do disappear:

>$ ps -efw | grep mongo
root      7041     1  4 21:29 ?        00:00:01 mongod --rest --fork --config /etc/mongod.conf

My question is whether this should be happening? I tried the same in Windows, and didn't see an issue. I'm sure this didn't manifest in Ubuntu until recently either (I upgraded from 2.6 to 3).

Upvotes: 0

Views: 405

Answers (1)

darioguarascio
darioguarascio

Reputation: 1087

I tried to run mongod --fork and I got:

about to fork child process, waiting until server is ready for connections.

I guess this means that the main process does some stuff before actually forking to the final listener porcess, and this stuff can be allocating the journal file. I also got the multiple process status you are describing.

I tried the same command without --fork and a there was no extra process.

So what you think is correct, the extra spawned mongod are there for preallocation, but only in --fork mode.

Anyway, using nohup at this point is useless, because if you run mongo with --fork you are sending it into background mode as well: your nohup log would record only something like :

about to fork child process, waiting until server is ready for connections. 
forked process: 7306 
child process started successfully, parent exiting

Upvotes: 1

Related Questions