Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

2.x #813

Open
wants to merge 90 commits into
base: master
Choose a base branch
from
Open

2.x #813

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
0a3da39
update monitor component
py8765 Aug 7, 2015
5481f90
add command
py8765 Aug 7, 2015
a35d73d
update constants
py8765 Aug 7, 2015
08a72f3
update node info prefix
py8765 Aug 7, 2015
338813f
update monitor
py8765 Aug 28, 2015
a0a58be
add component stop
py8765 Sep 6, 2015
a30d8a9
add zookeeper reconnect
py8765 Sep 9, 2015
4e777fb
redis registry implemention
Sep 24, 2015
c348a2c
bug fix
Sep 25, 2015
c9e42a6
update command interface
py8765 Sep 29, 2015
2b6ff5f
add command support from redis_cli
hzxuzhonghu Sep 29, 2015
6d03bfa
Merge branch '2.x' into redis-registry
hzxuzhonghu Sep 29, 2015
50b0737
update command execute sequence, first delete cmd
hzxuzhonghu Sep 29, 2015
8d2ae44
code format keep consistent with pomelo
hzxuzhonghu Sep 30, 2015
9bc3caa
update format
hzxuzhonghu Oct 8, 2015
45bb62b
update format
hzxuzhonghu Oct 8, 2015
085d742
fix CreateMode not defined
zhangmin510 Oct 9, 2015
5d574e6
remove unused code
py8765 Oct 14, 2015
46ad812
fix bug for redis registry, in case env not provided
hzxuzhonghu Oct 14, 2015
3c4b3e6
redismonitor stop cmd
hzxuzhonghu Oct 14, 2015
6776dc4
remove add&remove event
py8765 Oct 16, 2015
9c69634
unit test and jslint error fix
Oct 20, 2015
3a9e7cb
fix unit test error
Oct 20, 2015
b0c04f3
use strict: update strict mode
hzxuzhonghu Oct 20, 2015
ff26be7
add default serverType
py8765 Oct 20, 2015
3c008bc
update zkmonitor closure
py8765 Oct 20, 2015
0670f8e
fix lint warn
Oct 20, 2015
871db3c
fix application ut error
Oct 20, 2015
a5ef36f
ut update
Oct 20, 2015
725c16a
fix cmd.js ut and remove redis monitor component load
Oct 21, 2015
a98b5c6
update socket.io version
py8765 Oct 21, 2015
f0ac4f3
implement monitors commands
zhangmin510 Oct 16, 2015
34292b4
Merge branch '2.x' of https://github.com/NetEase/pomelo into 2.x
zhangmin510 Oct 22, 2015
f570144
update for socket.io
py8765 Oct 23, 2015
677074e
fix zkmonitor bug
py8765 Oct 23, 2015
c5710fd
update socket.io template
py8765 Oct 23, 2015
db2e354
update sioconnector template
py8765 Oct 26, 2015
51dceab
refine zkmonitor code
zhangmin510 Oct 27, 2015
39a1f80
redis-registry cmd support
hzxuzhonghu Oct 30, 2015
8a4fbef
send result move out cmd.js
hzxuzhonghu Oct 30, 2015
f16de8a
fix bug
hzxuzhonghu Oct 30, 2015
fae94b7
update monitor component error
py8765 Oct 30, 2015
33e8049
fix bug
hzxuzhonghu Oct 30, 2015
a16f6ef
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
hzxuzhonghu Nov 2, 2015
229381e
add default zk root node
py8765 Nov 2, 2015
d4357e4
remove unused log
py8765 Nov 2, 2015
8548261
fix server id bug
py8765 Nov 2, 2015
f084ed1
ugrade ws to 0.8.0
py8765 Nov 2, 2015
f5dda62
update server id config in curServer
py8765 Nov 2, 2015
d345d5e
support show cmd
hzxuzhonghu Nov 3, 2015
e82ba4d
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
hzxuzhonghu Nov 3, 2015
87c0d41
replace node-redis with ioredis to support redis cluster
hzxuzhonghu Nov 3, 2015
a46fb5f
fix jshint error
Nov 3, 2015
ca7bda7
update ws template
py8765 Nov 3, 2015
55874f7
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
py8765 Nov 3, 2015
9761d9d
remove unused log
py8765 Nov 4, 2015
d19f467
remove unused files
py8765 Nov 4, 2015
f1907bc
update https template
py8765 Nov 4, 2015
09f9e39
redis register immediately after redisMonitor loaded
hzxuzhonghu Nov 4, 2015
5c464fc
update socket.io wss
py8765 Nov 4, 2015
3854216
update sio connector parameter
py8765 Nov 4, 2015
2f45ae3
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
py8765 Nov 4, 2015
0f696c6
support 3 kind redis: single node & sentinel & cluster
hzxuzhonghu Nov 4, 2015
ead5022
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
hzxuzhonghu Nov 4, 2015
dac91d8
upgrade pomelo-rpc to 1.0.0
py8765 Nov 5, 2015
c4bb09f
update redis config parameters
py8765 Nov 5, 2015
8744135
modify default redis mode to single
hzxuzhonghu Nov 5, 2015
3755e12
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
hzxuzhonghu Nov 6, 2015
c1ec58d
remove unused show commands
py8765 Nov 6, 2015
46ca2c8
support pre_load serverInfo and other info
hzxuzhonghu Nov 6, 2015
b36876a
fix zookeepermonitor show command
zhangmin510 Nov 6, 2015
5e02666
bug fix
hzxuzhonghu Nov 6, 2015
17e29b9
Merge branch '2.x' of github.com:NetEase/pomelo into 2.x
hzxuzhonghu Nov 6, 2015
a122152
remove log info
hzxuzhonghu Nov 6, 2015
609588a
fix get handler info
zhangmin510 Nov 10, 2015
0cef773
upgrade pomelo-rpc to 1.0.1
py8765 Dec 3, 2015
4b0ffd2
remove redisMonitor's cluster mode
Dec 9, 2015
23481e6
upgrade pomelo-rpc to 1.0.2
py8765 Dec 21, 2015
737b4bc
upgrade pomelo-loader to 0.0.7
py8765 Jan 7, 2016
64686b7
remove clear proxy
py8765 Jan 8, 2016
52061fd
upgrade to 2.0.0-pre
py8765 Jan 14, 2016
993fd3f
add redis ping to redesmonitor
zhangmin510 Mar 18, 2016
59488b5
remove clear proxy
py8765 Jan 8, 2016
b88f858
upgrade to 2.0.0-pre
py8765 Jan 14, 2016
03edb68
merge origin/2.x to avoid force push
zhangmin510 Mar 18, 2016
0d5ad0f
upgrade to 2.0.0, update pomelo-rpc to 1.0.3
zhangmin510 Apr 26, 2016
dfd665d
Fixed a bug in redismonitor that crashed the app
Jun 29, 2016
b79a693
Merge pull request #854 from topfreegames/redismonitorfix
fantasyni Jan 20, 2017
de16fe9
Adds an alternative lighter redis monitor
mmacvicar Nov 16, 2016
99503ab
Merge pull request #905 from topfreegames/redismonitorlight
fantasyni Jan 23, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 3 additions & 276 deletions bin/pomelo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

"use strict";

/**
* Module dependencies.
*/
Expand All @@ -9,40 +11,25 @@ var fs = require('fs'),
util = require('util'),
cliff = require('cliff'),
mkdirp = require('mkdirp'),
co = require('../lib/modules/console'),
utils = require('../lib/util/utils'),
starter = require('../lib/master/starter'),
exec = require('child_process').exec,
spawn = require('child_process').spawn,
version = require('../package.json').version,
adminClient = require('pomelo-admin').adminClient,
constants = require('../lib/util/constants'),
program = require('commander');

/**
* Constant Variables
*/
var TIME_INIT = 1 * 1000;
var TIME_KILL_WAIT = 5 * 1000;
var KILL_CMD_LUX = 'kill -9 `ps -ef|grep node|awk \'{print $2}\'`';
var KILL_CMD_WIN = 'taskkill /im node.exe /f';

var CUR_DIR = process.cwd();
var DEFAULT_GAME_SERVER_DIR = CUR_DIR;
var DEFAULT_USERNAME = 'admin';
var DEFAULT_PWD = 'admin';
var DEFAULT_ENV = 'development';
var DEFAULT_MASTER_HOST = '127.0.0.1';
var DEFAULT_MASTER_PORT = 3005;

var CONNECT_ERROR = 'Fail to connect to admin console server.';
var FILEREAD_ERROR = 'Fail to read the file, please check if the application is started legally.';
var CLOSEAPP_INFO = 'Closing the application......\nPlease wait......';
var ADD_SERVER_INFO = 'Successfully add server.';
var RESTART_SERVER_INFO = 'Successfully restart server.';
var INIT_PROJ_NOTICE = '\nThe default admin user is: \n\n'+ ' username'.green + ': admin\n ' + 'password'.green+ ': admin\n\nYou can configure admin users by editing adminUser.json later.\n ';
var SCRIPT_NOT_FOUND = 'Fail to find an appropriate script to run,\nplease check the current work directory or the directory specified by option `--directory`.\n'.red;
var MASTER_HA_NOT_FOUND = 'Fail to find an appropriate masterha config file, \nplease check the current work directory or the arguments passed to.\n'.red;
var COMMAND_ERROR = 'Illegal command format. Use `pomelo --help` to get more info.\n'.red;
var DAEMON_INFO = 'The application is running in the background now.\n';

Expand All @@ -54,86 +41,6 @@ program.command('init [path]')
init(path || CUR_DIR);
});

program.command('start')
.description('start the application')
.option('-e, --env <env>', 'the used environment', DEFAULT_ENV)
.option('-D, --daemon', 'enable the daemon start')
.option('-d, --directory, <directory>', 'the code directory', DEFAULT_GAME_SERVER_DIR)
.option('-t, --type <server-type>,', 'start server type')
.option('-i, --id <server-id>', 'start server id')
.action(function(opts) {
start(opts);
});

program.command('list')
.description('list the servers')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function(opts) {
list(opts);
});

program.command('add')
.description('add a new server')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.args = args.slice(0, -1);
add(opts);
});

program.command('stop')
.description('stop the servers, for multiple servers, use `pomelo stop server-id-1 server-id-2`')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.serverIds = args.slice(0, -1);
terminal('stop', opts);
});

program.command('kill')
.description('kill the application')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.option('-f, --force', 'using this option would kill all the node processes')
.action(function() {
var args = [].slice.call(arguments, 0);
var opts = args[args.length - 1];
opts.serverIds = args.slice(0, -1);
terminal('kill', opts);
});

program.command('restart')
.description('restart the servers, for multiple servers, use `pomelo restart server-id-1 server-id-2`')
.option('-u, --username <username>', 'administration user name', DEFAULT_USERNAME)
.option('-p, --password <password>', 'administration password', DEFAULT_PWD)
.option('-h, --host <master-host>', 'master server host', DEFAULT_MASTER_HOST)
.option('-P, --port <master-port>', 'master server port', DEFAULT_MASTER_PORT)
.option('-t, --type <server-type>,', 'start server type')
.option('-i, --id <server-id>', 'start server id')
.action(function(opts) {
restart(opts);
});

program.command('masterha')
.description('start all the slaves of the master')
.option('-d, --directory <directory>', 'the code directory', DEFAULT_GAME_SERVER_DIR)
.action(function(opts) {
startMasterha(opts);
});

program.command('*')
.action(function() {
console.log(COMMAND_ERROR);
Expand Down Expand Up @@ -369,161 +276,6 @@ function start(opts) {
}
}

/**
* List pomelo processes.
*
* @param {Object} opts options for `list` operation
*/
function list(opts) {
var id = 'pomelo_list_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, {signal: 'list'}, function(err, data) {
if(err) {
console.error(err);
}
var servers = [];
for(var key in data.msg) {
servers.push(data.msg[key]);
}
var comparer = function(a, b) {
if (a.serverType < b.serverType) {
return -1;
} else if (a.serverType > b.serverType) {
return 1;
} else if (a.serverId < b.serverId) {
return -1;
} else if (a.serverId > b.serverId) {
return 1;
} else {
return 0;
}
};
servers.sort(comparer);
var rows = [];
rows.push(['serverId', 'serverType', 'pid', 'rss(M)', 'heapTotal(M)', 'heapUsed(M)', 'uptime(m)']);
servers.forEach(function(server) {
rows.push([server.serverId, server.serverType, server.pid, server.rss, server.heapTotal, server.heapUsed, server.uptime]);
});
console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green', 'cyan', 'magenta', 'white', 'yellow']));
process.exit(0);
});
});
}

/**
* Add server to application.
*
* @param {Object} opts options for `add` operation
*/
function add(opts) {
var id = 'pomelo_add_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, { signal: 'add', args: opts.args }, function(err) {
if(err) {
console.error(err);
}
else {
console.info(ADD_SERVER_INFO);
}
process.exit(0);
});
});
}

/**
* Terminal application.
*
* @param {String} signal stop/kill
* @param {Object} opts options for `stop/kill` operation
*/
function terminal(signal, opts) {
console.info(CLOSEAPP_INFO);
// option force just for `kill`
if(opts.force) {
if (os.platform() === constants.PLATFORM.WIN) {
exec(KILL_CMD_WIN);
} else {
exec(KILL_CMD_LUX);
}
process.exit(1);
return;
}
var id = 'pomelo_terminal_' + Date.now();
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, {
signal: signal, ids: opts.serverIds
}, function(err, msg) {
if(err) {
console.error(err);
}
if(signal === 'kill') {
if(msg.code === 'ok') {
console.log('All the servers have been terminated!');
} else {
console.log('There may be some servers remained:', msg.serverIds);
}
}
process.exit(0);
});
});
}

function restart(opts) {
var id = 'pomelo_restart_' + Date.now();
var serverIds = [];
var type = null;
if(!!opts.id) {
serverIds.push(opts.id);
}
if(!!opts.type) {
type = opts.type;
}
connectToMaster(id, opts, function(client) {
client.request(co.moduleId, { signal: 'restart', ids: serverIds, type: type}, function(err, fails) {
if(!!err) {
console.error(err);
} else if(!!fails.length) {
console.info('restart fails server ids: %j', fails);
} else {
console.info(RESTART_SERVER_INFO);
}
process.exit(0);
});
});
}

function connectToMaster(id, opts, cb) {
var client = new adminClient({username: opts.username, password: opts.password, md5: true});
client.connect(id, opts.host, opts.port, function(err) {
if(err) {
abort(CONNECT_ERROR + err.red);
}
if(typeof cb === 'function') {
cb(client);
}
});
}

/**
* Start master slaves.
*
* @param {String} option for `startMasterha` operation
*/
function startMasterha(opts) {
var configFile = path.join(opts.directory, constants.FILEPATH.MASTER_HA);
if(!fs.existsSync(configFile)) {
abort(MASTER_HA_NOT_FOUND);
}
var masterha = require(configFile).masterha;
for(var i=0; i<masterha.length; i++) {
var server = masterha[i];
server.mode = constants.RESERVED.STAND_ALONE;
server.masterha = 'true';
server.home = opts.directory;
runServer(server);
}
}

/**
* Check if the given directory `path` is empty.
*
Expand Down Expand Up @@ -617,7 +369,7 @@ function copy(origin, target) {
* @param {Function} fn
*/
function mkdir(path, fn) {
mkdirp(path, 0755, function(err){
mkdirp(path, '0755', function(err){
if(err) {
throw err;
}
Expand Down Expand Up @@ -653,29 +405,4 @@ function connectorType(cb) {
break;
}
});
}

/**
* Run server.
*
* @param {Object} server server information
*/
function runServer(server) {
var cmd, key;
var main = path.resolve(server.home, 'app.js');
if(utils.isLocal(server.host)) {
var options = [];
options.push(main);
for(key in server) {
options.push(util.format('%s=%s', key, server[key]));
}
starter.localrun(process.execPath, null, options);
} else {
cmd = util.format('cd "%s" && "%s"', server.home, process.execPath);
cmd += util.format(' "%s" ', main);
for(key in server) {
cmd += util.format(' %s=%s ', key, server[key]);
}
starter.sshrun(cmd, server.host);
}
}
9 changes: 7 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function(grunt) {
var src = ['test/manager/taskManager.js', 'test/filters/*.js',
'test/remote/*.js', 'test/service/*.js', 'test/modules/*.js', 'test/util/*.js', 'test/*.js'];


// Project configuration.
grunt.initConfig({
mochaTest: {
Expand All @@ -35,10 +36,14 @@ module.exports = function(grunt) {
}
},
jshint: {
all: ['lib/*']
all: ['lib/*'],
options: {
node: true,
sub: true
}
}
});

// Default task.
grunt.registerTask('default', ['clean', 'mochaTest', 'jshint']);
};
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
'use strict';
module.exports = require('./lib/pomelo');
Loading