diff --git a/CHANGELOG.md b/CHANGELOG.md index d940d818..174a4933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### 0.15.11 +- [#1825] Process management commands (start/restart/stop/delete) can take multiple arguments - [#1822] Add new method pm2.sendDataToProcessId(type|data|id) to send data to processes - [#1819] Send SIGINT signal to process instead of SIGTERM - [#1819][#1794][#1765] Avoid writing on std err/out when process is disconnected diff --git a/bin/pm2 b/bin/pm2 index 775f0027..a3021bb1 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -9,6 +9,7 @@ var p = path; var util = require('util'); var cronJob = require('cron').CronJob; var chalk = require('chalk'); +var async = require('async'); var debug = require('debug')('pm2:cli'); var Satan = require('../lib/Satan'); @@ -191,7 +192,7 @@ function failOnUnknown(fn) { // // Start command // -commander.command('start ') +commander.command('start ') .option('--watch', 'Watch folder for changes') .description('start and daemonize an app') .action(function(cmd) { @@ -204,7 +205,13 @@ commander.command('start ') }); } else { - CLI.start(cmd, commander); + async.forEachLimit(cmd, 1, function(script, next) { + CLI.start(script, commander, function() { + next(); + }); + }, function(err) { + CLI.list(); + }); } }); @@ -235,21 +242,34 @@ commander.command('startOrGracefulReload ') // // Stop specific id // -commander.command('stop ') +commander.command('stop ') .option('--watch', 'Stop watching folder for changes') .description('stop a process (to start it again, do pm2 restart )') .action(function(param) { - CLI.stop(param); + async.forEachLimit(param, 1, function(script, next) { + CLI.stop(script, function() { + next(); + }); + }, function(err) { + CLI.list(); + }); }); // // Stop All processes // -commander.command('restart ') +commander.command('restart ') .option('--watch', 'Toggle watching folder for changes') .description('restart a process') .action(function(param) { - CLI.restart(param); + + async.forEachLimit(param, 1, function(script, next) { + CLI.restart(script, function() { + next(); + }); + }, function(err) { + CLI.list(); + }); }); // @@ -288,7 +308,7 @@ commander.command('gracefulReload ') // // Stop and delete a process by name from database // -commander.command('delete ') +commander.command('delete ') .description('stop and delete a process from pm2 process list') .action(function(name) { if (name == "-") { @@ -299,7 +319,13 @@ commander.command('delete ') CLI.delete(param, 'pipe'); }); } else - CLI.delete(name,''); + async.forEachLimit(name, 1, function(script, next) { + CLI.delete(script,'', function(err) { + next(); + }); + }, function(err) { + CLI.list(); + }); }); // diff --git a/test/bash/multiparam.sh b/test/bash/multiparam.sh new file mode 100644 index 00000000..98ef7a41 --- /dev/null +++ b/test/bash/multiparam.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +SRC=$(cd $(dirname "$0"); pwd) +source "${SRC}/include.sh" + +cd $file_path + +############# TEST + +echo -e "\033[1mRunning tests:\033[0m" + +$pm2 kill +spec "kill daemon" + +## Start +$pm2 start child.js echo.js server.js +should 'should app be online' 'online' 3 + +## Restart +$pm2 restart child echo server +should 'should app be online' 'online' 3 +should 'should all script been restarted one time' 'restart_time: 1' 3 + +## Stop +$pm2 stop child echo server +should 'should app be stopped' 'stopped' 3 + +## Delete +$pm2 delete child echo server +shouldnot 'should app be deleted' 'stopped' 3 diff --git a/test/pm2_behavior_tests.sh b/test/pm2_behavior_tests.sh index 345ab78c..48b572ad 100644 --- a/test/pm2_behavior_tests.sh +++ b/test/pm2_behavior_tests.sh @@ -30,6 +30,8 @@ bash ./test/bash/smart-start.sh spec "smart start test" bash ./test/bash/cli.sh spec "CLI basic test" +bash ./test/bash/multiparam.sh +spec "Multiparam process management" bash ./test/bash/json_file.sh spec "JSON file test" bash ./test/bash/json-reload.sh