Skip to content

Commit

Permalink
#2486 add --web option to pm2-docker to expose web process api
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Nov 5, 2016
1 parent 1579079 commit 91a5eae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

## 2.1.X

- #2486 add --web option to pm2-docker command to expose web process api
- #2333 #2478 #1732 #1346 #1311 #1101 Fix GracefulShutdown SIGINT output + Better Stop process flow
- #2353 --wait-ready will wait that the application sends 'ready' event process.send('ready')
- #2425 allow to specify node.js version to be used or installed via interpreter 'node@VERSION'
Expand Down
8 changes: 8 additions & 0 deletions bin/pm2-docker
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ var pm2;
commander.version(pkg.version)
.option('--raw', 'raw log output')
.option('--json', 'output logs in json format')
.option('--web [port]', 'launch process web api on [port] default to 9615')
.option('--format', 'output logs formated like key=val')
.option('--only <application-name>', 'only act on one application of configuration')
.option('--secret [key]', 'keymetrics secret key')
.option('--secret [key]', 'keymetrics secret key')
.option('--public [key]', 'keymetrics public key')
.option('--machine-name [name]', 'keymetrics machine name')
.option('--auto-exit', 'exit if all processes are errored/stopped or 0 apps launched')
Expand All @@ -41,6 +43,12 @@ function start(cmd, opts) {
autoExit();

pm2.connect(function() {

if (opts.web) {
var port = opts.web === true ? cst.WEB_PORT : opts.web;
pm2.web(port);
}

run(cmd, opts);
});
}
Expand Down
12 changes: 10 additions & 2 deletions lib/API/Extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,23 @@ module.exports = function(CLI) {
* @method web
* @return
*/
CLI.prototype.web = function(cb) {
CLI.prototype.web = function(port, cb) {
var that = this;

if (typeof(port) === 'function') {
cb = port;
port = 9615;
}

var filepath = path.resolve(path.dirname(module.filename), '../HttpInterface.js');

that.start({
script : filepath,
name : 'pm2-http-interface',
execMode : 'fork_mode'
execMode : 'fork_mode',
env : {
PM2_WEB_PORT : port
}
}, function(err, proc) {
if (err) {
Common.printError(cst.PREFIX_MSG_ERR + 'Error while launching application', err.stack || err);
Expand Down
2 changes: 1 addition & 1 deletion lib/HttpInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function startWebServer(pm2) {
res.write(JSON.stringify({err : '404'}));
return res.end();
}
}).listen(cst.WEB_PORT, cst.WEB_IPADDR, function() {
}).listen(process.env.PM2_WEB_PORT || cst.WEB_PORT, cst.WEB_IPADDR, function() {
console.log('Web interface listening on %s:%s', cst.WEB_IPADDR, cst.WEB_PORT);
});

Expand Down

0 comments on commit 91a5eae

Please sign in to comment.