add kill and start parameters to daemon node

This commit is contained in:
Dave Conway-Jones
2017-05-03 17:46:10 +01:00
parent a3211a5e80
commit 0fb8a1a2a0
4 changed files with 34 additions and 17 deletions

View File

@@ -15,14 +15,23 @@ module.exports = function(RED) {
function inputlistener(msg) {
if (msg != null) {
if (!Buffer.isBuffer(msg.payload)) {
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
if (typeof msg.payload !== "string") { msg.payload = msg.payload.toString(); }
if (node.cr === true) { msg.payload += "\n"; }
if (msg.hasOwnProperty("kill") && node.running) {
if (typeof msg.kill !== "string" || msg.kill.length === 0 || !msg.kill.toUpperCase().startsWith("SIG") ) { msg.kill = "SIGINT"; }
node.child.kill(msg.kill.toUpperCase());
}
else if (msg.hasOwnProperty("start") && !node.running) {
runit();
}
else {
if (!Buffer.isBuffer(msg.payload)) {
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
if (typeof msg.payload !== "string") { msg.payload = msg.payload.toString(); }
if (node.cr === true) { msg.payload += "\n"; }
}
if (RED.settings.verbose) { node.log("inp: "+msg.payload); }
if (node.child !== null && node.running) { node.child.stdin.write(msg.payload); }
else { node.warn("Command not running"); }
}
if (RED.settings.verbose) { node.log("inp: "+msg.payload); }
if (node.child !== null) { node.child.stdin.write(msg.payload); }
else { node.warn("Command not running"); }
}
}
@@ -61,11 +70,13 @@ module.exports = function(RED) {
node.send([null,{payload:data},null]);
});
node.child.on('close', function (code) {
if (RED.settings.verbose) { node.log("ret: "+code); }
node.send([null,null,{payload:code}]);
node.child = null;
node.child.on('close', function (code,signal) {
if (RED.settings.verbose) { node.log("ret: "+code+":"+signal); }
node.running = false;
node.child = null;
var rc = code;
if (code === null) { rc = signal; }
node.send([null,null,{payload:rc}]);
node.status({fill:"red",shape:"ring",text:"stopped"});
});