wait for primary
This commit is contained in:
1 parent
cf6c16f674
commit
fb505278bd
2 files changed
+16
-15
No files matched your search
@@ -1,15 +1,16 @@
|
||||
try {
|
||||
const status = rs.status();
|
||||
printjson(status);
|
||||
} catch (e) {
|
||||
if (e.codeName === "NotYetInitialized") {
|
||||
print("Replica set not initialized. Initiating...");
|
||||
rs.initiate({
|
||||
_id: "rs0",
|
||||
members: [{ _id: 0, host: "mongodb:27017" }],
|
||||
});
|
||||
} else {
|
||||
print("Unexpected error during rs.status():");
|
||||
printjson(e);
|
||||
function waitForPrimary() {
|
||||
while (true) {
|
||||
try {
|
||||
rs.initiate({
|
||||
_id: "rs0",
|
||||
members: [{ _id: 0, host: "localhost:27017" }],
|
||||
});
|
||||
break;
|
||||
} catch (e) {
|
||||
print("Replica set initiation failed, retrying in 2s...");
|
||||
sleep(2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
waitForPrimary();
|
||||
Reference in new issue
Block a user