mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
merge fix pr #181
This commit is contained in:
commit
3a78dad99a
27
lib/God.js
27
lib/God.js
@ -11,6 +11,7 @@ var util = require('util');
|
||||
var log = require('debug')('pm2:god');
|
||||
var fs = require('fs');
|
||||
var Common = require('./Common');
|
||||
var os = require('os');
|
||||
|
||||
var EventEmitter2 = require('eventemitter2').EventEmitter2;
|
||||
|
||||
@ -303,9 +304,9 @@ God.prepare = function(env, cb) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Allows an app to be prepared using the same json format as the CLI, instead
|
||||
* Allows an app to be prepared using the same json format as the CLI, instead
|
||||
* of the internal PM2 format.
|
||||
* An array of applications is not currently supported. Call this method
|
||||
* An array of applications is not currently supported. Call this method
|
||||
* multiple times with individual app objects if you have several to start.
|
||||
* @param app {Object}
|
||||
* @param [cwd] {string} Optional string to specify the cwd for the script.
|
||||
@ -317,11 +318,11 @@ God.prepareJson = function (app, cwd, cb) {
|
||||
cb = cwd;
|
||||
cwd = undefined;
|
||||
}
|
||||
|
||||
|
||||
app = Common.resolveAppPaths(app, cwd);
|
||||
if (app instanceof Error)
|
||||
return cb(app);
|
||||
|
||||
|
||||
return God.prepare(app, cb);
|
||||
};
|
||||
|
||||
@ -400,6 +401,24 @@ God.getMonitorData = function(env, cb) {
|
||||
ex(processes.length - 1);
|
||||
};
|
||||
|
||||
God.getSystemData = function(env, cb) {
|
||||
God.getMonitorData(env, function(err, processes) {
|
||||
cb(err, {
|
||||
system: {
|
||||
hostname: os.hostname(),
|
||||
uptime: os.uptime(),
|
||||
cpus: os.cpus(),
|
||||
load: os.loadavg(),
|
||||
memory: {
|
||||
free: os.freemem(),
|
||||
total: os.totalmem()
|
||||
}
|
||||
},
|
||||
processes: processes
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
God.getFormatedProcesses = function() {
|
||||
var db = God.clusters_db;
|
||||
var arr = [];
|
||||
|
||||
@ -109,6 +109,7 @@ Satan.remoteWrapper = function() {
|
||||
prepare : God.prepare,
|
||||
prepareJson : God.prepareJson,
|
||||
getMonitorData : God.getMonitorData,
|
||||
getSystemData : God.getSystemData,
|
||||
startProcessId : God.startProcessId,
|
||||
stopProcessId : God.stopProcessId,
|
||||
stopProcessName : God.stopProcessName,
|
||||
|
||||
@ -21,6 +21,7 @@ describe('God', function() {
|
||||
God.should.have.property('prepare');
|
||||
God.should.have.property('getProcesses');
|
||||
God.should.have.property('getMonitorData');
|
||||
God.should.have.property('getSystemData');
|
||||
God.should.have.property('getFormatedProcesses');
|
||||
God.should.have.property('checkProcess');
|
||||
God.should.have.property('stopAll');
|
||||
|
||||
@ -52,6 +52,7 @@ describe('Satan', function() {
|
||||
assert(err == null);
|
||||
methods.should.have.property('prepare');
|
||||
methods.should.have.property('getMonitorData');
|
||||
methods.should.have.property('getSystemData');
|
||||
methods.should.have.property('stopProcessId');
|
||||
methods.should.have.property('stopAll');
|
||||
methods.should.have.property('stopProcessName');
|
||||
@ -67,6 +68,13 @@ describe('Satan', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get an empty process list from system data', function(done) {
|
||||
Satan.executeRemote('getSystemData', {}, function(err, res) {
|
||||
assert(res.processes.length === 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should launch a process', function(done) {
|
||||
Satan.executeRemote('prepare', {
|
||||
pm_exec_path : path.resolve(process.cwd(), 'test/fixtures/echo.js'),
|
||||
@ -87,5 +95,12 @@ describe('Satan', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should list 4 processes via system data', function(done) {
|
||||
Satan.executeRemote('getSystemData', {}, function(err, res) {
|
||||
assert(res.processes.length === 4);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user