希望能出一个无master的版本

原来的2.0.0版本就很好
依靠zookeeper集群
没有master,可以随意增减各个服务
不存在master死,整个服务器死掉的问题

标签: pomelo
joe001 在 4-19 23:10发布 分享到 weibo
3 回复
#1 arachide 4-23 14:57 回复

赞同

#2 lwcbest 5-3 15:07 回复

利用pm2加载 就可以了 不用care master
var env = 'production';
var servers = require('../../config/env/version/servers.json')[env];
var master = require('../../config/env/version/master.json')[env];
var fs = require('fs');

var _RESULT = {};

for (var serverType in servers) {
servers[serverType].forEach(function (conf) {
console.log(conf);
var process = {
"name" : "",
"cwd" : "../../",
"script" : "app.js",
"args" : null,
"exec_mode" : "fork",
"watch" : false,
"env" : {
"NODE_ENV": env
},
"merge_logs" : true,
"autorestart" : true,
"max_memory_restart": "1G"
};
process.name = conf.id;
var args = [];
args.push("env="+env);
args.push("serverType=" + serverType);
for (var k in conf) {
args.push(k + "=" + conf[k]);
}
process.args = args;

    var destHost = conf.host;
    if (_RESULT.hasOwnProperty(destHost)) {
        _RESULT[destHost].apps.push(process);
    } else {
        _RESULT[destHost] = {};
        _RESULT[destHost]['apps'] = [];
        _RESULT[destHost].apps.push(process);
    }
});

}

fs.writeFileSync('./master@' + master.host + '.json', JSON.stringify({
"apps": [{
"name" : master.id,
"cwd" : "../../",
"script" : "app.js",
"args" : [
"serverType=master",
"id=" + master.id,
"host=" + master.host,
"port=" + master.port,
"env=" + env,
"mode=stand-alone"
],
"exec_mode" : "fork",
"watch" : false,
"env" : {
"NODE_ENV": env
},
"merge_logs" : true,
"autorestart" : true,
"max_memory_restart": "1G"
}]
}, null, 2), {
flag: 'w'
});

for (var host in RESULT) {
fs.writeFileSync('./' + host + '.json', JSON.stringify(
RESULT[host], null, 2), {
flag: 'w'
});
}

#3 lwcbest 5-3 15:07 回复

这个是pm2 加载文件 的generator

回到顶部