Mongodb sharding – Init script for mongos process

mongodb

I've been running mongodb as a replica set, and have recently attempted to move to a sharded cluster.

One thing I'm a little unsure about is how I should be starting the mongos process. Previously I had used the 10gen rpms when installing mongodb, which installed an init.d script for the mongod service. I'd like to have mongos run in a similar way, but am unsure about how I should be doing this really. Is it a case of writing a custom init script?

I'm on Debian 6, and Mongodb 2.4

[I'd previously posted this quesion in the mongodb google group, but am copying here as I didn't get any response – I'll add any responses here too]

Best Answer

You have linked the relevant official request for this in your answer and SERVER-3748 does explain some of the reasons why these don't currently exist.

The most basic reason is that you cannot start mongos without at least one config server being up and working, otherwise it will refuse to start, which makes it a poor candidate for an init script (external dependencies). Generally you want to avoid having services that are going to fail to start when there is no good way to check the reason for failure.

However, it would still be beneficial to give people a script rather than having them modify/write one themselves, hence the Jira issue exists.

The way I would recommend to do this is to base any script off of the existing mongod init script and simply modify it to replace mongod with mongos where appropriate. Here is the current version of that script for Debian:

https://github.com/mongodb/mongo/blob/master/debian/init.d

Things you will need to change:

> DAEMON=/usr/bin/mongos
> DESC=mongos-router
> 
> NAME=mongos
> 
> CONF=/etc/mongos.conf 
> PIDFILE=/var/run/$NAME.pid 
> ENABLE_MONGODB=yes

The advantage to doing this, after you have installed the 10gen package, is that the users will already be set up and you have the mongod script for reference on the system.

You will need to create the config file with appropriate values for your mongos, and there might be a couple of other things you need to tweak - the key is to test before you make anything permanent.

Once you confirm via testing that you have the script working as you wish, then you can add it permanently with update-rc.d

Related Topic