From ab516f654354cf81d87ac8c6276f02f9998ee034 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 8 Jan 2016 11:15:54 -0800 Subject: [PATCH] Add forceful shutdown of processes if no response after 2.5s --- console/src/modules/hf-process.js | 33 +++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/console/src/modules/hf-process.js b/console/src/modules/hf-process.js index 0f4104d2c8..60a24bb804 100755 --- a/console/src/modules/hf-process.js +++ b/console/src/modules/hf-process.js @@ -204,18 +204,39 @@ Process.prototype = extend(Process.prototype, { this.updateState(ProcessStates.STARTED); this.emit('logs-updated'); }, - stop: function() { - if (this.state != ProcessStates.STARTED) { - console.warn("Can't stop process that is not started."); + stop: function(force) { + if (this.state == ProcessStates.STOPPED) { + console.warn("Can't stop process that is not started or stopping."); return; } if (os.type() == "Windows_NT") { - childProcess.spawn("taskkill", ["/pid", this.child.pid, '/f', '/t']); + var command = "taskkill /pid " + this.child.pid; + if (force) { + command += " /f /t"; + } + childProcess.exec(command, {}, function(error) { + if (error) { + console.error('Error executing taskkill:', error); + } + }); } else { - this.child.kill(); + var signal = force ? 'SIGKILL' : null; + this.child.kill(signal); } - this.state = ProcessStates.STOPPING; + console.log("Stopping child process:", this.child.pid, this.name); + + if (!force) { + this.stoppingTimeoutID = setTimeout(function() { + if (this.state == ProcessStates.STOPPING) { + console.log("Force killling", this.name, this.child.pid); + this.stop(true); + } + }.bind(this), 2500); + } + + this.updateState(ProcessStates.STOPPING); + }, updateState: function(newState) { if (this.state != newState) { this.state = newState;