Skip to content

Commit

Permalink
修复sample文件夹被误删的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwindworld committed Dec 11, 2017
1 parent 2d613b1 commit c3bfba5
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sample/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"sealEngine": "PBFT",
"systemproxyaddress":"0x0",
"systemproxyaddressDfsFile":"",
"systemproxyaddressDfsServer":"",
"listenip":"{ip}",
"rpcport":"{rpcport}",
"p2pport":"{p2pport}",
"wallet":"{nodedir}keys.info",
"keystoredir":"{nodedir}keystore/",
"datadir":"{nodedir}data/",
"vm":"interpreter",
"networkid":"{networkid}",
"logverbosity":"4",
"coverlog":"OFF",
"eventlog":"ON",
"logconf":"{nodedir}log.conf",
"dfsNode":"",
"dfsGroup":"group1",
"dfsStorage":"filestorage",
"params": {
"accountStartNonce": "0x0",
"maximumExtraDataSize": "0x0",
"tieBreakingGas": false,
"blockReward": "0x0",
"networkID" : "0x0"
},
"NodeextraInfo":{nodeextrainfo}
}
13 changes: 13 additions & 0 deletions sample/genesis.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"nonce": "0x0",
"difficulty": "0x0",
"mixhash": "0x0",
"coinbase": "0x0",
"timestamp": "0x0",
"parentHash": "0x0",
"extraData": "0x0",
"gasLimit": "0x13880000000000",
"god":"{admin}",
"alloc": {},
"initMinerNodes":{initMinerNodes}
}
137 changes: 137 additions & 0 deletions sample/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
var fs=require('fs');
var execSync =require('child_process').execSync;

var options = process.argv;
if( options.length < 3 )
{
console.log('Usage: node init.js node0.sample node1.sample node2.sample... ');
process.exit(0);
}

var nodeconfiglength=0;
var nodeconfig=[];
while(nodeconfig.length<options.length-2 ){
var node=JSON.parse(fs.readFileSync(options[2+nodeconfig.length], 'utf-8'));
nodeconfig.push(node);
}

console.log("开始检查配置...");
var check=true;
for( var i=0;i<nodeconfig.length;i++){
for( var j=0;j<nodeconfig.length;j++){
if( i!=j ){
if( nodeconfig[i].networkid != nodeconfig[j].networkid){
check=false;
console.log('节点'+i+'和节点'+j+' networkid不一致,请检查!');
}
if( nodeconfig[i].ip == nodeconfig[j].ip ){
if( nodeconfig[i].nodedir == nodeconfig[j].nodedir ){
console.log('节点'+i+',和节点'+j+' IP相同且datadir相同,请检查!');
check=false;
}
if( nodeconfig[i].rpcport == nodeconfig[j].rpcport ){
console.log('节点'+i+',和节点'+j+' IP相同且rpcport相同,请检查!');
check=false;
}
if( nodeconfig[i].p2pport == nodeconfig[j].p2pport ){
console.log('节点'+i+',和节点'+j+' IP相同且p2pport相同,请检查!');
check=false;
}
}
}
}
}
if( !check ){
process.exit(1);
}
else{
console.log('配置检查成功!!!');
}

var admin;
try{
admin=execSync("node ../tool/accountManager.js");
console.log('生成管理员账户成功!!!即将拷贝备份到每个节点目录的admin.message文件中,请注意保管!!!');
}catch(e){
console.log('管理员账户生成失败!!!');
process.exit(1);
}

var nodeid=[];
console.log('开始初始化节点配置...');
for( var i=0;i<nodeconfig.length;i++){
try{
execSync("mkdir -p "+nodeconfig[i].nodedir);
execSync("mkdir -p "+nodeconfig[i].nodedir+"log/");
execSync("mkdir -p "+nodeconfig[i].nodedir+"data/");
execSync("mkdir -p "+nodeconfig[i].nodedir+"keystore/");
execSync("bcoseth --gennetworkrlp "+nodeconfig[i].nodedir+"data/network.rlp");
nodeid.push(fs.readFileSync(nodeconfig[i].nodedir+"data/network.rlp.pub", 'utf-8'));

var logconfig=fs.readFileSync("log.conf.template", 'utf-8');
fs.writeFileSync(nodeconfig[i].nodedir+'log.conf',logconfig.replace(/{nodedir}/g,nodeconfig[i].nodedir));

var startsh=fs.readFileSync("start.sh.template", 'utf-8');
startsh=startsh.replace(/{genesis}/g,nodeconfig[i].nodedir+'genesis.json');
fs.writeFileSync(nodeconfig[i].nodedir+'start'+i+'.sh',startsh.replace(/{config}/g,nodeconfig[i].nodedir+'config.json'));
execSync("chmod -x "+nodeconfig[i].nodedir+'start'+i+'.sh');

fs.writeFileSync(nodeconfig[i].nodedir+'admin.message',admin);
console.log('节点'+i+'目录生成成功!!!');
}catch(e){
console.log('节点'+i+'目录生成失败!'+e);
}

}//for

admin=fs.readFileSync(nodeconfig[0].nodedir+'admin.message','utf-8');
admin=(admin.split(/\n/)[2].split(/ /)[2]);

var genesis=fs.readFileSync("genesis.json.template", 'utf-8');
genesis=genesis.replace(/{initMinerNodes}/g,JSON.stringify(nodeid));
genesis=genesis.replace(/{admin}/g,admin);
console.log('创世文件生成成功!!!');

var nodeextrainfo=[];
for( var i=0;i<nodeconfig.length;i++){
nodeextrainfo.push({
"Nodeid":nodeid[i],
"Nodedesc": "node"+i,
"Agencyinfo": "node"+i,
"Peerip": nodeconfig[i].ip,
"Identitytype": 1,
"Port":nodeconfig[i].p2pport,
"Idx":i
});
}
console.log('记账节点列表生成成功!!!');

for( var i=0;i<nodeconfig.length;i++){
try{
fs.writeFileSync(nodeconfig[i].nodedir+'genesis.json',genesis);
console.log('节点'+i+' genesis.json生成成功!!!');


var config=fs.readFileSync("config.json.template", 'utf-8');
config=config.replace(/{nodedir}/g,nodeconfig[i].nodedir);
config=config.replace(/{networkid}/g,nodeconfig[i].networkid);
config=config.replace(/{ip}/g,nodeconfig[i].ip);
config=config.replace(/{rpcport}/g,nodeconfig[i].rpcport);
config=config.replace(/{p2pport}/g,nodeconfig[i].p2pport);
config=config.replace(/{nodeextrainfo}/g,JSON.stringify(nodeextrainfo));

fs.writeFileSync(nodeconfig[i].nodedir+'config.json',config);

console.log('节点'+i+' config.json生成成功!!!');
}catch(e){
console.log('节点'+i+' 配置生成失败!'+e);
}

}//for
console.log('恭喜!已全部构建成功!');

for( var i=0;i<nodeconfig.length;i++){
console.log('执行 '+nodeconfig[i].nodedir+'start'+i+'.sh 即可启动节点'+i);
}


29 changes: 29 additions & 0 deletions sample/log.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
* GLOBAL:
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = false
FORMAT = "%level|%datetime{%Y-%M-%d %H:%m:%s}|%msg"
FILENAME = "{nodedir}log/log_%datetime{%Y%M%d%H}.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 209715200 ## 200MB - Comment starts with two hashes (##)
LOG_FLUSH_THRESHOLD = 100 ## Flush after every 100 logs

* TRACE:
FILENAME = "{nodedir}log/trace_log_%datetime{%Y%M%d%H}.log"
* DEBUG:
FILENAME = "{nodedir}log/debug_log_%datetime{%Y%M%d%H}.log"
* FATAL:
FILENAME = "{nodedir}log/fatal_log_%datetime{%Y%M%d%H}.log"

* ERROR:
FILENAME = "{nodedir}log/error_log_%datetime{%Y%M%d%H}.log"

* WARNING:
FILENAME = "{nodedir}log/warn_log_%datetime{%Y%M%d%H}.log"

* INFO:
FILENAME = "{nodedir}log/info_log_%datetime{%Y%M%d%H}.log"

* VERBOSE:
ENABLED = false
7 changes: 7 additions & 0 deletions sample/node0.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"networkid":"123456",
"nodedir":"/bcos-data/node0/",
"ip":"127.0.0.1",
"rpcport":8545,
"p2pport":30303
}
7 changes: 7 additions & 0 deletions sample/node1.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"networkid":"123456",
"nodedir":"/bcos-data/node1/",
"ip":"127.0.0.1",
"rpcport":8546,
"p2pport":30304
}
6 changes: 6 additions & 0 deletions sample/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
node init.js node0.sample node1.sample
chmod +x /bcos-data/node0/start0.sh
chmod +x /bcos-data/node1/start1.sh
sh /bcos-data/node0/start0.sh &
sh /bcos-data/node1/start1.sh &
3 changes: 3 additions & 0 deletions sample/start.sh.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
bcoseth --genesis {genesis} --config {config}

0 comments on commit c3bfba5

Please sign in to comment.