I created a sharding in local environment for testing purpose.
I have three config server on 1 machine and 1 query router on same machine and two data nodes on two different machines.
Everything works fine but my problem is I am unable to keep all process active running on different ports as I don't have any start / stop script. I run processes on command line with &
in the end to make it active which is very poor way to keep proces active and sometime it dies automatically.
Please help or provide a way to use scripts and also script can handle various ports to active all process on single machine.
You shouldn't never be looking to drive multiple instances from one init script, as this creates a whole amount of excess administrative work when you are doing startup/shutdown of any one of the instances.
You should look to have one init script for each individual database process instance as this is Linux best practice.
For the most part you should be able to use the generic MongoDB provided init script and then make a renamed copy for each database instance.
You should then create individual config files for each instance, which should contain slightly different configurations and run each instance on its own port, own dbpath and own logfile.
You can then point each init script at the config file for its instance and everything should work as planned.
Finally, within MongoDB, you should use the --fork option, which provides a safe way to detach MongoDB from a shell instance. If you absolutely must continue using shell fork (the & operator) then you should wrap MongoDB in "nohup" to avoid having the instance closed by a termination of your shell. This would look something like:
nohup <mongodb cmd and arguments> &
Edit:
You can use the same process to use the same init scripts to launch MongoS. You need to find the line which sets the mongod
binary as the one to be executed. Under all of the debian derivatives this would be the DAEMON
variable. Change this to point to mongos
instead of mongod
and off you go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With