Fixed conflict between pm2 kill and watcher restart

This commit is contained in:
jshkurti 2015-03-12 17:12:49 +01:00
parent a37ff8ca03
commit d9fd10e3cb
4 changed files with 19 additions and 2 deletions

View File

@ -1418,6 +1418,7 @@ CLI.ilogs = function() {
CLI.killDaemon = function(cb) {
printOut(cst.PREFIX_MSG + 'Stopping PM2...');
Satan.executeRemote('notifyKillPM2', {}, function() {});
CLI.killAllModules(function() {
CLI._operate('deleteProcessId', 'all', function(err, list) {
printOut(cst.PREFIX_MSG + 'All processes has been stopped and deleted');

View File

@ -150,6 +150,14 @@ module.exports = function(God) {
return cb(null, {msg : 'pong'});
};
/**
* Description
* @method notifyKillPM2
*/
God.notifyKillPM2 = function() {
God.pm2_being_killed = true;
};
/**
* Start a stopped process by ID
* @method startProcessId
@ -335,8 +343,13 @@ module.exports = function(God) {
Common.extend(proc.pm2_env.env, opts.env);
if (proc.pm2_env.status == cst.ONLINE_STATUS) {
if (God.pm2_being_killed) {
return cb('PM2 is being killed, stopping restart procedure...');
}
if (proc.pm2_env.status === cst.ONLINE_STATUS) {
God.stopProcessId(id, function(err) {
if (God.pm2_being_killed)
return cb('PM2 is being killed, stopping restart procedure...');
proc.pm2_env.restart_time += 1;
return God.startProcessId(id, cb);
});
@ -345,7 +358,7 @@ module.exports = function(God) {
}
else {
debug('[restart] process not online, starting it');
God.startProcessId(id, cb);
return God.startProcessId(id, cb);
}
return false;
};

View File

@ -112,6 +112,8 @@ module.exports = function(God) {
return cb(God.logAndGenerateError('Unknown process'), {});
async.eachLimit(processes, cst.CONCURRENT_ACTIONS, function(proc, next) {
if (God.pm2_being_killed)
return next('[Watch] PM2 is being killed, stopping restart procedure...');
if (proc.pm2_env.status === cst.ONLINE_STATUS)
return God.restartProcessId({id:proc.pm2_env.pm_id}, next);
else if (proc.pm2_env.status !== cst.STOPPING_STATUS

View File

@ -188,6 +188,7 @@ Satan.remoteWrapper = function() {
notifyByProcessId : God.notifyByProcessId,
killMe : God.killMe,
notifyKillPM2 : God.notifyKillPM2,
findByScript : God.findByScript,
findByPort : God.findByPort,