-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose some pm2 cli interface via hubot command. #21
Comments
💯 |
You can use This is an example snippet which handle pm2 via Express.
/** Module depdendencies. */
var pm2 = require('pm2'),
Promise = require('bluebird'),
fs = require('fs'),
_ = require('underscore');
/** PM2 Promises */
var pm2connect = Promise.promisify(pm2.connect),
pm2list = Promise.promisify(pm2.list),
pm2restart = Promise.promisify(pm2.restart),
pm2stop = Promise.promisify(pm2.stop);
var DevOps = module.exports = exports = {};
DevOps.getPM2List = function (req, res) {
pm2connect().then(function () {
return pm2list();
}).then(function (list) {
res.send(list);
}).catch(function (e) {
res.sendException(500, {reason: e.message});
});
};
DevOps.PM2Restart = function (req, res) {
pm2connect().then(function () {
return pm2restart(process.env.PM2_APP_NAME);
}).then(function () {
return pm2.list();
}).then(function (list) {
res.send(list);
}).catch(function (e) {
res.sendException(500, {reason: e.message});
});
};
DevOps.PM2Stop = function (req, res) {
pm2connect().then(function () {
return pm2stop(process.env.PM2_APP_NAME);
}).then(function () {
return pm2.list();
}).then(function (list) {
res.send(list);
}).catch(function (e) {
res.sendException(500, {reason: e.message});
});
};
DevOps.getPM2StdoutLog = function (req, res) {
pm2connect().then(function () {
return pm2list();
}).then(function (list) {
fs.createReadStream(_.pluck(list, 'pm2_env')[0]['pm_out_log_path'])
.pipe(res);
}).catch(function (e) {
res.sendException(500, {reason: e.message});
});
};
DevOps.getPM2StderrLog = function (req, res) {
pm2connect().then(function () {
return pm2list();
}).then(function (list) {
fs.createReadStream(_.pluck(list, 'pm2_env')[0]['pm_err_log_path'])
.pipe(res);
}).catch(function (e) {
res.sendException(500, {reason: e.message});
});
}; |
@mooyoul cool !! that really can help us 🙇 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if we can restart hubot on chat room (like
hubot restart
), it could be nice.we can control pm2 on script.
The text was updated successfully, but these errors were encountered: