diff --git a/CHANGELOG.md b/CHANGELOG.md index 97be1fb3..05e61048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - #2663 allow to directly output json when logging (via log_type for JSON and --log-type via CLI) - #2675 fix path when installing language module like typescript - #2674 increase restart timeout for systemd startup +- #2564 allow to operate process (restart/reload/stop/delete) with regex ## 2.3.0 diff --git a/lib/API.js b/lib/API.js index 91794fec..6a927ef3 100644 --- a/lib/API.js +++ b/lib/API.js @@ -1311,7 +1311,7 @@ API.prototype._operate = function(action_name, process_name, envs, cb) { } // operate using regex else if (isNaN(process_name) && process_name[0] === '/' && process_name[process_name.length - 1] === '/') { - var regex = new RegExp(process_name); + var regex = new RegExp(process_name.replace(/\//g, '')); that.Client.executeRemote('getMonitorData', {}, function(err, list) { if (err) { @@ -1324,7 +1324,7 @@ API.prototype._operate = function(action_name, process_name, envs, cb) { found_proc.push(proc.pm_id); } }); - + if (found_proc.length === 0) { Common.printError(conf.PREFIX_MSG_WARNING + 'No process found'); return cb ? cb(new Error('process name not found')) : that.exitCli(conf.ERROR_EXIT); diff --git a/test/bash/operate-regex.sh b/test/bash/operate-regex.sh new file mode 100644 index 00000000..86e59fa8 --- /dev/null +++ b/test/bash/operate-regex.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +SRC=$(cd $(dirname "$0"); pwd) +source "${SRC}/include.sh" + +cd $file_path + +$pm2 start echo.js --name "echo-3" +$pm2 start echo.js --name "echo-1" +$pm2 start echo.js --name "echo-2" + +sleep 0.5 + +should 'should have started 3 apps' 'online' 3 + +$pm2 stop /echo-[1,2]/ + +should 'should have stopped 2 apps' 'stopped' 2 +should 'only one app should still be online' 'online' 1 + +$pm2 stop /echo-3/ +should 'should have stopped 1 apps' 'online' 0 + +$pm2 restart /echo-[1,2]/ + +should 'should have restarted 2 apps' 'online' 2 + diff --git a/test/pm2_behavior_tests.sh b/test/pm2_behavior_tests.sh index 9a59e530..418bf3bf 100644 --- a/test/pm2_behavior_tests.sh +++ b/test/pm2_behavior_tests.sh @@ -121,6 +121,8 @@ bash ./test/bash/log-null.sh spec "Logging path set to null" bash ./test/bash/log-json.sh spec "Logging directly to file in json" +bash ./test/bash/operate-regex.sh +spec "Operate process that match regex" # Issues related bash ./test/bash/issues/2337.sh