From 55ec8df4bb17a4b86a4ec45044effa2eefe2c272 Mon Sep 17 00:00:00 2001 From: Unitech Date: Mon, 14 Dec 2015 18:46:48 +0100 Subject: [PATCH] #1810 add --kill-timeout option to configure delay before SIGKILL --- bin/pm2 | 1 + lib/God/Methods.js | 17 ++++++++++------- lib/schema.json | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/pm2 b/bin/pm2 index 5764e44e..e269e860 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -32,6 +32,7 @@ commander.version(pkg.version) .option('-o --output ', 'specify out log file') .option('-e --error ', 'specify error log file') .option('-p --pid ', 'specify pid file') + .option('-k --kill-timeout ', 'delay before sending final SIGKILL signal to process') .option('--max-memory-restart ', 'specify max memory amount used to autorestart (in megaoctets)') .option('--restart-delay ', 'specify a delay between restarts (in milliseconds)') .option('--env ', 'specify environment to get specific env variables (for JSON declaration)') diff --git a/lib/God/Methods.js b/lib/God/Methods.js index f032c72f..a30e86ec 100644 --- a/lib/God/Methods.js +++ b/lib/God/Methods.js @@ -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); }; /** diff --git a/lib/schema.json b/lib/schema.json index ca8b8ab5..34af4602 100644 --- a/lib/schema.json +++ b/lib/schema.json @@ -33,6 +33,9 @@ "instances": { "type": "number" }, + "kill_timeout": { + "type": "number" + }, "port": { "type": "number" },