Created
August 6, 2015 04:21
-
-
Save Hochul822/165ef7a26545308851e4 to your computer and use it in GitHub Desktop.
Gist Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'); | |
var exec = require('child_process').exec; | |
var zookeeper = require('node-zookeeper-client'); | |
var root_shard_path = '/shard1'; | |
var replSet = "arbiter"; | |
function exists(client){ | |
client.exists(root_shard_path, | |
function(event){ | |
console.log('Got event : %s.', event); | |
exists(client, path); | |
}, | |
function(error, stat){ | |
if(error){ | |
console.log('Failed to check existence of node : %s due to : %s.', path, error ); | |
} | |
if(stat){ | |
replication(client, root_shard_path, replSet); | |
} else{ | |
shard(client, root_shard_path); | |
replication(client, root_shard_path, replSet); | |
} | |
return; | |
} | |
); | |
} | |
function replication(client, path, replSet){ | |
client.create(path + "/" + replSet, new Buffer(''), zookeeper.CreateMode.EPHEMERAL, function(err, path){ | |
if(err){ | |
console.log('Failed to create node : %s due to %s', shard, err); | |
}else{ | |
console.log('Node : %s is successfully created', shard ); | |
} | |
return; | |
}); | |
} | |
function start() { | |
var client = zookeeper.createClient('localhost:2181'); | |
client.once('connected', function () { | |
exists(client); | |
}); | |
client.connect(); | |
exec("mongod --port 20017 --dbpath /data/db/replSet_Arbiter --replSet Mongo_study --smallfiles --noprealloc --nojournal --logpath /data/db/replSet_Log/mongo-replSet_Arbiter.log", function(err, stdout, stderr) { | |
console.log(stdout); | |
client.close(); | |
}); | |
} | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment