make daemon node kill/term/int selectable

This commit is contained in:
Dave Conway-Jones 2018-05-09 09:42:51 +01:00
parent 31cee79545
commit 5b69ab66aa
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 26 additions and 5 deletions

View File

@ -28,6 +28,14 @@
<option value="number">try to convert reply to a number</option>
</select>
</div>
<div class="form-row">
<label for="node-input-closer"> on close</label>
<select id="node-input-closer" style='width:70%'>
<option value="SIGKILL">kill process immediately</option>
<option value="SIGTERM">try to terminate process</option>
<option value="SIGINT">try to interrupt process</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
@ -51,12 +59,13 @@
category: 'advanced-function',
color:"darksalmon",
defaults: {
name: {value:""},
command: {value:"",required:true},
args: {value:""},
cr: {value:false},
redo: {value:true},
op: {value:"string"},
name: {value:""}
closer: {value:"SIGKILL"}
},
inputs:1,
outputs:3,

View File

@ -11,6 +11,7 @@ module.exports = function(RED) {
this.op = n.op;
this.redo = n.redo;
this.running = false;
this.closer = n.closer || "SIGKILL";
var node = this;
function inputlistener(msg) {
@ -110,10 +111,21 @@ module.exports = function(RED) {
node.on("close", function(done) {
clearInterval(loop);
if (node.child != null) { node.child.kill('SIGKILL'); }
if (RED.settings.verbose) { node.log(node.cmd+" stopped"); }
if (node.child != null) {
var tout;
node.child.on('exit', function() {
if (tout) { clearTimeout(tout); }
done();
});
tout = setTimeout(function() {
node.child.kill("SIGKILL"); // if it takes more than 3 secs kill it anyway.
done();
}, 3000);
node.child.kill(node.closer);
if (RED.settings.verbose) { node.log(node.cmd+" stopped"); }
}
else { setTimeout(function() { done(); }, 100); }
node.status({});
setTimeout(function() { done(); }, 100);
});
runit();

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-daemon",
"version" : "0.0.20",
"version" : "0.0.21",
"description" : "A Node-RED node that runs and monitors a long running system command.",
"dependencies" : {
},