mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-12-27 07:21:08 +01:00
add kill and start parameters to daemon node
This commit is contained in:
@@ -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"});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user