Permalink
Browse files

resolve conflicts

Change-Id: I5994b455c98d9ac4865f24f0ad064f50e55bbf08
  • Loading branch information...
2 parents ecf9afa + 50c1bb5 commit c1b7a8acb6fadf4ffdf13b8870f55fa48e5fe433 @changchang changchang committed Jan 5, 2013
Showing with 68 additions and 76 deletions.
  1. +2 −0 .gitignore
  2. +37 −55 bin/pomelo
  3. +5 −2 lib/master/master.js
  4. +1 −2 lib/master/starter.js
  5. +14 −13 lib/modules/console.js
  6. +1 −1 lib/pomelo.js
  7. +4 −3 package.json
  8. +4 −0 template/npm-install.bat
View
@@ -12,3 +12,5 @@ node_modules/*
*.sublime-project
*.sublime-workspace
lib/doc/
+lib-cov/
+coverage.html
View
@@ -3,16 +3,18 @@
/**
* Module dependencies.
*/
-var fs = require('fs'),
- path = require('path'),
- util = require('util'),
- cliff = require('cliff'),
- cp = require('child_process'),
- exec = cp.exec,
- spawn = cp.spawn,
- co = require('../lib/modules/console'),
- utils = require('../lib/util/utils'),
- adminClient = require('pomelo-admin').adminClient;
+var fs = require('fs')
+ , os = require('os')
+ , path = require('path')
+ , util = require('util')
+ , cliff = require('cliff')
+ , mkdirp = require('mkdirp')
+ , co = require('../lib/modules/console')
+ , utils = require('../lib/util/utils')
+ , exec = require('child_process').exec
+ , spawn = require('child_process').spawn
+ , version = require('../package.json').version
+ , adminClient = require('pomelo-admin').adminClient;
/**
* Common Variables
@@ -32,7 +34,8 @@ var HOME = IF_HOME ? CUR_DIR : path.join(CUR_DIR, 'game-server');
var LOGS_DIR = IF_HOME ? path.join(CUR_DIR, 'logs') : path.join(CUR_DIR, 'game-server/logs');
var MASTER_CONFIG = path.resolve(HOME, 'config/master.json');
var TMP_FILE = path.resolve(LOGS_DIR, 'tmp');
-var KILL_CMD = 'kill -9 `ps -ef|grep node|awk \'{print $2}\'`';
+var KILL_CMD_LUX = 'kill -9 `ps -ef|grep node|awk \'{print $2}\'`';
+var KILL_CMD_WIN = 'taskkill /im node.exe /f';
var MASTER_JSON;
var NOWORKSPACE_ERROR = 'Please go to your game-server directory to start the application.';
@@ -44,15 +47,11 @@ var STOPSERVER_ERROR = 'Fail to stop server.';
var FILEREAD_ERROR = 'Fail to read the file, please check if the application is started legally.';
var RUNDAEMON_INFO = 'Application run in daemon.\nStop the application use the command:pomelo stop.';
var CLOSEAPP_INFO = 'Closing the application......\nPlease wait......';
-/**
- * Usage documentation.
- */
-var usage = '' + '\n' + ' Usage: pomelo [action] [option]\n' + '\n' + ' Options:\n' + ' init [path] create new application\n' + ' start [option] start the application\n' + ' list list server information\n' + ' stop stop the application\n' + ' kill [--force] kill the application\n' + ' version output framework version\n' + ' help output help information\n' + ' [option] developement(default)/production --daemon';
/**
- * Framework version.
+ * Usage documentation.
*/
-var version = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'))).version;
+var usage = '' + '\n' + ' Usage: pomelo [action] [option]\n' + '\n' + ' Options:\n' + ' init [path] create new application\n' + ' start [option] start the application\n' + ' list list server information\n' + ' stop stop the application\n' + ' kill [--force] kill the application\n' + ' version output framework version\n' + ' help output help information\n' + ' [option] developement(default)/production --daemon';
/**
* Parse command arguments.
@@ -124,8 +123,8 @@ function init(path) {
function createApplicationAt(ph) {
var name = path.basename(path.resolve(CUR_DIR, ph));
copy(path.join(__dirname, '../template/'), ph);
- mkdir(path.join(ph, 'game-server/logs'), 0755);
- mkdir(path.join(ph, 'shared'), 0755);
+ mkdir(path.join(ph, 'game-server/logs'));
+ mkdir(path.join(ph, 'shared'));
setTimeout(function() {
var repalcefile = [path.resolve(ph, 'game-server/app.js'), path.resolve(ph, 'game-server/package.json'), path.resolve(ph, 'web-server/package.json')];
for(var i = 0; i < repalcefile.length; i++) {
@@ -208,13 +207,13 @@ function list() {
}
var msg = data.msg;
var rows = [];
- rows.push(['serverId', 'serverType', 'pid', 'cpuAvg', 'memAvg', 'time']);
+ rows.push(['serverId', 'serverType', 'pid', 'heapUsed(M)', 'uptime(m)']);
for(var key in msg) {
var server = msg[key];
- rows.push([server['serverId'], server['serverType'], server['pid'], server['cpuAvg'], server['memAvg'], server['time']]);
+ rows.push([server['serverId'], server['serverType'], server['pid'], server['heapUsed'], server['uptime']]);
}
- console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green', 'white', 'yellow', 'grey']));
- process.exit(1);
+ console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green', 'white', 'yellow']));
+ process.exit(0);
});
}
});
@@ -233,7 +232,7 @@ function terminal(signal) {
if(IF_WORKSPACE) {
console.info(CLOSEAPP_INFO);
if(args[0] === '--force') {
- exec(KILL_CMD);
+ os.platform() === 'win32' ? exec(KILL_CMD_WIN):exec(KILL_CMD_LUX);
process.exit(1);
}
fs.readFile(TMP_FILE, function(err, data) {
@@ -246,7 +245,7 @@ function terminal(signal) {
setTimeout(function() {
if(IF_HOME) exec('forever stop app.js');
else exec('cd game-server && forever stop app.js');
- process.exit(1);
+ process.exit(0);
}, TIME_KILL_WAIT);
}
client.connect(id, config.host, config.port, function(err) {
@@ -257,17 +256,15 @@ function terminal(signal) {
if(err) abort(STOPSERVER_ERROR);
if(msg.status === "error") abort(STOPSERVER_ERROR);
setTimeout(function() {
- exec(KILL_CMD);
fs.unlinkSync(TMP_FILE);
- process.exit(1);
+ process.exit(0);
}, TIME_KILL_WAIT);
});
});
});
} else abort(NOWORKSPACE_ERROR);
};
-
/**
* Check if the given directory `path` is empty.
*
@@ -336,8 +333,8 @@ function legalArgNum(argNum) {
function copy(origin, target) {
if(!fs.existsSync(origin)) abort(origin + 'is not exist.');
if(!fs.existsSync(target)) {
- mkdir(target, 0);
- console.log('Make dir: ' + target);
+ mkdir(target);
+ console.log(' \x1b[36mcreate\x1b[0m : ' + target);
}
fs.readdir(origin, function(err, datalist) {
if(err) abort(FILEREAD_ERROR);
@@ -346,37 +343,22 @@ function copy(origin, target) {
var tCurrent = path.resolve(target, datalist[i]);
if(fs.statSync(oCurrent).isFile()) {
fs.writeFileSync(tCurrent, fs.readFileSync(oCurrent, ''), '');
- console.log('Create file: ' + tCurrent);
+ console.log(' \x1b[36mcreate\x1b[0m : ' + tCurrent);
} else if(fs.statSync(oCurrent).isDirectory()) copy(oCurrent, tCurrent);
}
});
};
/**
- * Make directory for new project.
+ * Mkdir -p.
*
* @param {String} path
- * @param {Number} mode
+ * @param {Function} fn
*/
-function mkdir(url, mode) {
- var arr = url.split('/');
- mode = mode || 0755;
- switch(arr[0]) {
- case '.':
- arr.shift();
- break;
- case '..':
- arr.splice(0, 2, arr[0] + '/' + arr[1]);
- break;
- case '':
- arr[0] = "/";
- break;
- };
-
- function inner(cur) {
- if(!fs.existsSync(cur)) fs.mkdirSync(cur, mode);
- if(arr.length) inner(cur + '/' + arr.shift());
- }
- arr.length && inner(arr.shift());
- console.log('Make dir: ' + url);
-};
+function mkdir(path, fn) {
+ mkdirp(path, 0755, function(err){
+ if (err) throw err;
+ console.log(' \033[36mcreate\033[0m : ' + path);
+ fn && fn();
+ });
+}
View
@@ -5,6 +5,7 @@ var admin = require('pomelo-admin');
var AfterStart = require('../modules/afterStart');
var util = require('util');
var pathUtil = require('../util/pathUtil');
+var os = require('os');
/**
* master server
@@ -54,7 +55,8 @@ Server.prototype.start = function(cb) {
};
Server.prototype.stop = function(cb) {
- this.masterConsole.stop(cb);
+ this.masterConsole.stop();
+ process.nextTick(cb);
};
var checkRegistered = function(master) {
@@ -108,6 +110,7 @@ var registerDefaultModules = function(app) {
app.registerAdmin(admin.modules.nodeInfo);
app.registerAdmin(admin.modules.monitorLog,{path: pathUtil.getLogPath(app.getBase())});
app.registerAdmin(admin.modules.scripts, {app: app, path: pathUtil.getScriptPath(app.getBase())});
- app.registerAdmin(admin.modules.profiler, {isMaster: true});
+ if(os.platform() !== 'win32')
+ app.registerAdmin(admin.modules.profiler, {isMaster: true});
}
};
View
@@ -68,8 +68,7 @@ starter.kill = function(app, pids, serverIds) {
if(!server) {
continue;
}
-
- cmd = util.format('kill -9 %s', pids[i]);
+ os.platform() === 'win32' ? cmd = util.format('taskkill /pid %s /f', pids[i]):cmd = util.format('kill -9 %s', pids[i]);
if(isLocal(server.host)) {
starter.localrun(cmd);
} else {
View
@@ -8,6 +8,7 @@ var monitor = require('pomelo-monitor');
var countDownLatch = require('../util/countDownLatch');
var utils = require('../util/utils');
var TIME_WAIT_KILL = 5000;
+var TIME_WAIT_STOP = 3000;
module.exports = function(opts) {
return new Module(opts);
@@ -24,20 +25,18 @@ var Module = function(opts) {
Module.prototype.monitorHandler = function(agent, msg, cb) {
if(msg.signal === 'stop') {
+ if(agent.type === 'master') return;
this.app.stop(true);
} else {
var serverId = agent.id;
+ var serverType = agent.type;
var pid = process.pid;
- var params = {
- serverId: serverId,
- pid: pid
- };
- monitor.psmonitor.getPsInfo(params, function(err, data) {
- cb({
- serverId: agent.id,
- body: data
+ var heapUsed = (process.memoryUsage().heapUsed/(1000 * 1000)).toFixed(2);
+ var uptime = (process.uptime()/60).toFixed(2);
+ cb({
+ serverId: serverId,
+ body: {serverId:serverId, serverType: serverType, pid:pid, heapUsed:heapUsed, uptime:uptime}
});
- });
}
};
@@ -67,10 +66,12 @@ Module.prototype.clientHandler = function(agent, msg, cb) {
agent.notifyAll(module.exports.moduleId, {
signal: msg.signal
});
- self.app.stop(true);
- cb(null, {
- status: "ok"
- });
+ setTimeout(function(){
+ self.app.stop(true);
+ cb(null, {
+ status: "ok"
+ });
+ },TIME_WAIT_STOP);
} else {
var serverInfo = {};
var count = utils.size(agent.idMap);
View
@@ -24,7 +24,7 @@ var Pomelo = module.exports = {};
* Framework version.
*/
-Pomelo.version = '0.1';
+Pomelo.version = '0.2.x';
/**
* auto loaded components
View
@@ -1,6 +1,6 @@
{
"name":"pomelo",
- "version":"0.2.2",
+ "version":"0.2.4",
"private":false,
"dependencies": {
"socket.io":">=0.9.4",
@@ -9,10 +9,11 @@
"seq-queue":">=0.0.5",
"crc":">=0.0.1",
"cliff": ">=0.1.8",
+ "mkdirp": "0.3.3",
"pomelo-loader":"0.0.4",
"pomelo-rpc":"0.0.11",
- "pomelo-protocol":">=0.0.3",
- "pomelo-admin":"0.0.17",
+ "pomelo-protocol":"0.0.3",
+ "pomelo-admin":"0.0.18",
"pomelo-monitor":">=0.3.5",
"pomelo-logger": "0.0.2"
},
View
@@ -0,0 +1,4 @@
+::npm-install.bat
+@echo off
+::install web server dependencies && game server dependencies
+cd web-server && npm install -d && cd .. && cd game-server && npm install -d

0 comments on commit c1b7a8a

Please sign in to comment.