Skip to content

Commit

Permalink
feat: pm2 pid <app_name> command
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Feb 2, 2018
1 parent 65d233e commit 6687d49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ commander.command('startOrReload <json>')
pm2._startJson(file, commander, 'reloadProcessId');
});

commander.command('pid [app_name]')
.description('return pid of [app_name] or all')
.action(function(app) {
pm2.getPID(app);
});

commander.command('startOrGracefulReload <json>')
.description('start or gracefully reload JSON file')
.action(function(file) {
Expand Down
28 changes: 28 additions & 0 deletions lib/API/Extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,34 @@ module.exports = function(CLI) {
});
};

CLI.prototype.getPID = function(app_name, cb) {
var that = this;

if (typeof(app_name) === 'function') {
cb = app_name;
app_name = null;
}

this.Client.executeRemote('getMonitorData', {}, function(err, list) {
if (err) {
Common.printError(cst.PREFIX_MSG_ERR + err);
return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
}

var pids = [];

list.forEach(function(app) {
if (!app_name || app_name == app.name)
pids.push(app.pid);
})

if (!cb) {
Common.printOut(pids.join("\n"))
return that.exitCli(cst.SUCCESS_EXIT);
}
return cb(null, pids);
})
}
/**
* Create PM2 memory snapshot
* @method getVersion
Expand Down

0 comments on commit 6687d49

Please sign in to comment.