简体   繁体   中英

starting mongodb single server as replica set to enable oplog through supervisord

I want to start a single mongod instance with command mongod --config config/mongod.conf Once above process starts running I also have to call mongodb/bin/mongo --eval rs.initiate() Now the issue is I am starting mongod through supervisord I want to perform both of the above operation one after another. supervisord takes just 1 command to start the process which is first command. I have no other place to run the rs.initiate(). If I put both the command in shell script even then the control will be stuck with the first command itself.

Perhaps you could combine the commands into a single command. Ie,

mongod --config config/mongod.conf && sleep 5 && mongodb/bin/mongo --eval rs.initiate()

The sleep command assumes 5 seconds is enough for the mongod to come up and be available for an rs.initiate(). Given you are initiating a replica set I assume you have no data? If so, startup should be relatively quickly. Also if you are attempting to make a single node replica set you might want to consider...

rs.initiate (
    {
        _id: "somereplicasetname",
        version: 1,
        members:
        [
            { _id: 0, host: "somehostname:27017" }
        ]
    }
)

... so that you don't need to configure the initiated replicaset any further. The _id value (currently showing as somereplicasetname ) is expected to match the replica set name in the config file mongod.conf and the somehostname is expected to resolve to the current host.

By the way, I assume you recognize you only need to initialize a replica set once, not every time you start the mongod process..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM