mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
postExec command on PMD
This commit is contained in:
parent
c79dc951c8
commit
4dcd448a9f
@ -9,7 +9,7 @@
|
||||
- Much better Module system with raw NPM feedback
|
||||
- Better Windows support
|
||||
- **pm2-docker** command with his official [Docker image](https://github.com/keymetrics/pm2-docker-alpine)
|
||||
- **pm2-dev** command enhanced
|
||||
- **pm2-dev -> pmd** command enhanced (better log output, post-exec cmd)
|
||||
- Watch and Reload instead of Watch and Restart
|
||||
- New PM2 API, backward compatible with previous PM2 versions
|
||||
|
||||
|
||||
@ -14,12 +14,15 @@ var Common = require('./Common');
|
||||
var chalk = require('chalk');
|
||||
var path = require('path');
|
||||
var fmt = require('./tools/fmt.js');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
process.env.PM2_SILENT = 'true';
|
||||
|
||||
commander.version(pkg.version)
|
||||
.option('--raw', 'raw log output')
|
||||
.option('--ignore [files]', 'files to ignore while watching')
|
||||
.option('--post-exec [cmd]', 'execute extra command after change detected')
|
||||
.option('--silent-exec', 'do not output result of post command', false)
|
||||
.usage('[cmd] app');
|
||||
|
||||
var pm2 = new PM2.custom({
|
||||
@ -30,6 +33,28 @@ pm2.connect(function() {
|
||||
commander.parse(process.argv);
|
||||
});
|
||||
|
||||
function postExecCmd(command, cb) {
|
||||
var exec_cmd = exec(command);
|
||||
|
||||
if (commander.silentExec !== true) {
|
||||
exec_cmd.stdout.on('data', function(data) {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
|
||||
exec_cmd.stderr.on('data', function(data) {
|
||||
process.stderr.write(data);
|
||||
});
|
||||
}
|
||||
|
||||
exec_cmd.on('close', function done() {
|
||||
if (cb) cb(null);
|
||||
});
|
||||
|
||||
exec_cmd.on('error', function (err) {
|
||||
console.error(err.stack || err);
|
||||
});
|
||||
};
|
||||
|
||||
function run(cmd, opts) {
|
||||
var timestamp = commander.timestamp;
|
||||
|
||||
@ -61,8 +86,20 @@ function run(cmd, opts) {
|
||||
fmt.field('Processes started', chalk.bold(procs.length));
|
||||
fmt.field('Watch and Restart', chalk.green('Enabled'));
|
||||
fmt.field('Ignored folder', commander.ignore_watch || 'node_modules');
|
||||
if (commander.postExec)
|
||||
fmt.field('Post restart cmd', commander.postExec);
|
||||
fmt.sep();
|
||||
|
||||
setTimeout(function() {
|
||||
pm2.Client.launchBus(function(err, bus) {
|
||||
bus.on('process:event', function(packet) {
|
||||
if (packet.event == 'online') {
|
||||
postExecCmd(commander.postExec);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
Log.devStream(pm2.Client, 'all', commander.raw, timestamp, false);
|
||||
|
||||
process.on('SIGINT', function() {
|
||||
@ -82,9 +119,8 @@ commander.command('*')
|
||||
run(cmd, opts);
|
||||
});
|
||||
|
||||
commander.command('run <file|json_file>')
|
||||
.alias('start')
|
||||
.description('run <file|json_file> in development mode')
|
||||
commander.command('start <file|json_file>')
|
||||
.description('start target config file/script in development mode')
|
||||
.action(function(cmd, opts) {
|
||||
run(cmd, opts);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user