#1810 add --kill-timeout <number> option to configure delay before SIGKILL

This commit is contained in:
Unitech 2015-12-14 18:46:48 +01:00
parent ba95a80387
commit 55ec8df4bb
3 changed files with 14 additions and 7 deletions

View File

@ -32,6 +32,7 @@ commander.version(pkg.version)
.option('-o --output <path>', 'specify out log file')
.option('-e --error <path>', 'specify error log file')
.option('-p --pid <pid>', 'specify pid file')
.option('-k --kill-timeout <delay>', 'delay before sending final SIGKILL signal to process')
.option('--max-memory-restart <memory>', 'specify max memory amount used to autorestart (in megaoctets)')
.option('--restart-delay <delay>', 'specify a delay between restarts (in milliseconds)')
.option('--env <environment_name>', 'specify environment to get specific env variables (for JSON declaration)')

View File

@ -204,10 +204,11 @@ module.exports = function(God) {
* @param {} cb
* @return Literal
*/
God.processIsDead = function(pid, cb, sigkill) {
God.processIsDead = function(pid, pm2_env, cb, sigkill) {
if (!pid) return cb({type : 'param:missing', msg : 'no pid passed'});
var timeout = null;
var timeout = null;
var kill_timeout = (pm2_env && pm2_env.kill_timeout) ? pm2_env.kill_timeout : cst.KILL_TIMEOUT;
var timer = setInterval(function() {
if (God.checkProcess(pid) === false) {
@ -229,11 +230,13 @@ module.exports = function(God) {
else {
console.log('Process with pid %d still alive after %sms, sending it SIGKILL now...', pid, cst.KILL_TIMEOUT);
try {
crossPlatformGroupKill(parseInt(pid),'SIGKILL');
} catch(e) { console.error('Process cannot be killed', e.message || e.stack || e); }
return God.processIsDead(pid, cb, true);
crossPlatformGroupKill(parseInt(pid), 'SIGKILL');
} catch(e) {
console.error('Process cannot be killed', e.message || e.stack || e);
}
return God.processIsDead(pid, pm2_env, cb, true);
}
}, cst.KILL_TIMEOUT);
}, kill_timeout);
return false;
};
@ -266,7 +269,7 @@ module.exports = function(God) {
return cb(null, 'Cannot be killed');
}
return God.processIsDead(pid, cb);
return God.processIsDead(pid, pm2_env, cb);
};
/**

View File

@ -33,6 +33,9 @@
"instances": {
"type": "number"
},
"kill_timeout": {
"type": "number"
},
"port": {
"type": "number"
},