From a37c2d231da2be033d40a8d61a82876cb41545b3 Mon Sep 17 00:00:00 2001 From: soyuka Date: Wed, 28 Jun 2017 21:10:14 +0200 Subject: [PATCH] fix #2114 #2018 array names --- lib/Common.js | 4 ---- lib/Watcher.js | 8 ++++---- test/bash/misc.sh | 9 +++++++++ test/fixtures/push.json | 5 +++++ 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/push.json diff --git a/lib/Common.js b/lib/Common.js index 14df2823..aaeb2f27 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -112,10 +112,6 @@ Common.prepareAppConf = function(opts, app) { if (!app.script) return new Error('No script path - aborting'); - // Forbidden application name - if (app.name == 'push') - return new Error('Push application name is not allowed'); - if (app.automation == false) app.pmx = false; diff --git a/lib/Watcher.js b/lib/Watcher.js index d6abc1f4..6697de02 100644 --- a/lib/Watcher.js +++ b/lib/Watcher.js @@ -17,7 +17,7 @@ module.exports = function ClusterMode(God) { */ God.watch = {}; - God.watch._watchers = []; + God.watch._watchers = {}; God.watch.enable = function(pm2_env) { @@ -51,7 +51,7 @@ module.exports = function ClusterMode(God) { var watcher = chokidar.watch(watch, watch_options); - console.log('[Watch] Start watching', pm2_env.pm_id); + console.log('[Watch] Start watching', pm2_env.name); watcher.on('all', function(event, path) { var self = this; @@ -97,7 +97,7 @@ module.exports = function ClusterMode(God) { var watchers = God.watch._watchers; console.log('[Watch] PM2 is being killed. Watch is disabled to avoid conflicts'); - for (var i = 0; i < watchers.length; ++i) { + for (var i in watchers) { watchers[i].close && watchers[i].close(); watchers.splice(i, 1); } @@ -105,7 +105,7 @@ module.exports = function ClusterMode(God) { God.watch.disable = function(pm2_env) { if (God.watch._watchers[pm2_env.name]) { - console.log('[Watch] Stop watching', pm2_env.pm_id); + console.log('[Watch] Stop watching', pm2_env.name); God.watch._watchers[pm2_env.name].close(); delete God.watch._watchers[pm2_env.name]; return true; diff --git a/test/bash/misc.sh b/test/bash/misc.sh index b772e583..42dbb45a 100644 --- a/test/bash/misc.sh +++ b/test/bash/misc.sh @@ -7,6 +7,15 @@ cd $file_path echo -e "\033[1mRunning tests:\033[0m" +## Try to launch an app with `push` as name +$pm2 kill + +$pm2 start push.json + +$pm2 stop push.json + +$pm2 list + # # Max memory auto restart option # diff --git a/test/fixtures/push.json b/test/fixtures/push.json new file mode 100644 index 00000000..e5a8a9f2 --- /dev/null +++ b/test/fixtures/push.json @@ -0,0 +1,5 @@ +[{ + "name" : "push", + "script" : "echo.js", + "max" : "1" +}]