Skip to content

Commit

Permalink
Worker: restart process if using 0 memory and status equals ONLINE
Browse files Browse the repository at this point in the history
  • Loading branch information
jshkurti committed Nov 21, 2014
1 parent d3d2bcc commit c2e3581
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/pm2
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ commander.command('kill')
// Update repository for a given app
//

commander.command('pull <name> [commit id]')
commander.command('pull <name> [commit_id]')
.description('updates repository for a given app')
.action(function(pm2_name, commit_id) {
if (commit_id !== undefined) {
Expand Down
26 changes: 21 additions & 5 deletions lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit c2e3581

Please sign in to comment.