diff --git a/bin/pm2 b/bin/pm2 index 076a88bd..54d42499 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -516,7 +516,7 @@ commander.command('kill') // Update repository for a given app // -commander.command('pull [commit id]') +commander.command('pull [commit_id]') .description('updates repository for a given app') .action(function(pm2_name, commit_id) { if (commit_id !== undefined) { diff --git a/lib/Worker.js b/lib/Worker.js index 437dda26..79ea1b84 100644 --- a/lib/Worker.js +++ b/lib/Worker.js @@ -20,12 +20,12 @@ module.exports = function(God) { if (!(proc && proc.pm2_env && - proc_key.monit && - proc_key.monit.memory !== undefined && - proc.pm2_env.max_memory_restart !== undefined)) + proc_key.monit)) return cb(); - if (proc.pm2_env.max_memory_restart < (proc_key.monit.memory / (1024*1024))) { + if (proc_key.monit.memory !== undefined && + proc.pm2_env.max_memory_restart !== undefined && + proc.pm2_env.max_memory_restart < (proc_key.monit.memory / (1024*1024))) { console.log('[PM2][WORKER] Process %s restarted because it exceeds --max-memory-restart value', proc.pm2_env.pm_id); God.restartProcessId({ @@ -37,8 +37,24 @@ module.exports = function(God) { return cb(); }); } - else + else if (proc.pm2_env.status !== undefined && + proc_key.monit.memory !== undefined && + proc.pm2_env.status === cst.ONLINE_STATUS && + proc_key.monit.memory === 0) { + console.log('[PM2][WORKER] Process %s restarted because it uses 0 memory and has ONLINE status', + proc.pm2_env.pm_id); + God.restartProcessId({ + id: proc.pm2_env.pm_id, + env: proc.pm2_env.env + }, function(err, data) { + if (err) + console.error(err.stack || err); + return cb(); + }); + } + else { return cb(); + } }; var versioningRefresh = function(proc_key, cb) {