Automatic start of mongos and mongod

1,262 views
Skip to first unread message

Jorge Escobar

unread,
Aug 13, 2012, 12:29:04 PM8/13/12
to mongod...@googlegroups.com
Hi all,

I've been searching on the web and on this group, but I don't see an exact answer to the following question.

How can I make mongos and mongod restart automatically if a server is rebooted?

Here's my mongos command:
mongos --fork --logpath /var/log/mongo/mongod.log --configdb mongo01:27019,mongo02:27019,mongo03:27019

And my mongod command varies per server. If it's one of the servers with config, I run these two commands:
mongod --rest --fork --logpath /var/log/mongo/mongod.log --replSet stgshard1/mongo02:27017
mongod --fork --logpath /var/log/mongo/configd.log --configsvr

If it's a server without a config, I'll run:
mongod --rest --fork --logpath /var/log/mongo/mongod.log --replSet shard3/mongo06:27017

I know there's a config file that you can setup so that I can potentially run:
chckconfig mongod on

But not sure if that will work with mongos.

My servers run Red Hat Enterprise Linux 5.5.

Any help is appreciated.

markh

unread,
Aug 13, 2012, 12:51:34 PM8/13/12
to mongod...@googlegroups.com
Hi Jorge,

For Redhat, these are the recommended instructions.

What's the output of "chkconfig --list|grep mongo"?

To enable mongod to run at start-up as per the above instructions, run (with root privileges) - 

chkconfig mongod on

as you said. 

To cover your different servers, simply modify the relevant /etc/mongodb.conf file.

There's no such option with mongos due to the various dependencies (such as shards being up). However, you could create your own start-up scripts to do likewise with mongod.

Thanks

Mark 

Russell Bateman

unread,
Aug 13, 2012, 12:55:32 PM8/13/12
to mongod...@googlegroups.com
Mark,

Would you mind posting similar instructions for Ubuntu or a link? Other platforms? This is really just based on how services are managed, right?

Russ
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Jorge Escobar

unread,
Aug 13, 2012, 1:57:34 PM8/13/12
to mongod...@googlegroups.com
Thanks Mark. Your instructions pointed me in the right direction.

This is what I ended up doing, posting here for folks searching for this (this is works for RedHat installations).

Automatic restarting for mongo services is done adding an autostart script as follows:

- Create a script on /etc/init.d/mymongo, below one for application servers (mongos app servers):
#!/bin/sh
#
# chkconfig: 345 99 01
#
# description: your script is a test service
#
case $1 in
       start)
           echo "ogmongo starting"

           mongos --fork --logpath /var/log/mongo/mongod.log --configdb mongo01:27019,mongo02:27019,mongo03:27019
           ;;
       restart)
           echo "your script stopping"
           echo "your script starting"
           # TODO:
           ;;
       status)
           echo "your script running"
           # TODO:
           ;;
       stop)
           echo "your script stopping"
           # TODO:
           ;;
esac

- And here’s one for mongodb servers (do not put the configsrvr param on mongodb servers that do not have the configs on them. Also make sure that the replSets are properly set):
#!/bin/sh
#
# chkconfig: 345 99 01
#
# description: your script is a test service
#
case $1 in
       start)
           echo "ogmongo starting"

           mongod --fork --logpath /var/log/mongo/configd.log --configsvr
           mongod --rest --fork --logpath /var/log/mongo/mongod.log --replSet shard1/mongo02:27017
           ;;
       restart)
           echo "your script stopping"
           echo "your script starting"
           # TODO:
           ;;
       status)
           echo "your script running"
           # TODO:
           ;;
       stop)
           echo "your script stopping"
           # TODO:
           ;;
esac

- Modify permissions:
chmod 0755 /etc/init.d/mymongo


- Create a symlink on rc.3:
cd /etc/rc.d/rc3.d/
ln -s ../init.d/mymongo S99mymongo

- Add to chkconfig:
chkconfig --add mymongo

- Add to chkconfig:
chkconfig mymongo on

- You can check if the service is properly set by running (make sure mongod is set to off):
[root@og-stg-cloud01 ~]# chkconfig --list|grep mongo
mongod          0:off 1:off 2:off 3:off 4:off 5:off 6:off
mymongo         0:off 1:off 2:on 3:on 4:on 5:on 6:off



markh

unread,
Aug 13, 2012, 2:29:06 PM8/13/12
to mongod...@googlegroups.com
Thanks for sharing Jorge.

Russ,

Please see here for Ubuntu and Debian.

MacOSX is here but it doesn't contain control scripts unlike the Ubuntu and Red Hat packages.

Thanks

Mark
Reply all
Reply to author
Forward
0 new messages