mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add try/catch to daemon
This commit is contained in:
parent
3b20b804ae
commit
bb3d302bcb
@ -36,15 +36,16 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
function runit() {
|
||||
var line = "";
|
||||
if (!node.cmd || (typeof node.cmd !== "string") || (node.cmd.length < 1)) {
|
||||
node.status({fill:"grey",shape:"ring",text:"no command"});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
node.child = spawn(node.cmd, node.args);
|
||||
if (RED.settings.verbose) { node.log(node.cmd+" "+JSON.stringify(node.args)); }
|
||||
node.status({fill:"green",shape:"dot",text:"running"});
|
||||
node.running = true;
|
||||
var line = "";
|
||||
|
||||
node.child.stdout.on('data', function (data) {
|
||||
if (node.op === "string") { data = data.toString(); }
|
||||
@ -86,9 +87,17 @@ module.exports = function(RED) {
|
||||
if (err.errno === "ENOENT") { node.warn('Command not found'); }
|
||||
else if (err.errno === "EACCES") { node.warn('Command not executable'); }
|
||||
else { node.log('error: ' + err); }
|
||||
node.status({fill:"grey",shape:"dot",text:"error"});
|
||||
node.status({fill:"red",shape:"ring",text:"error"});
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
if (e.errno === "ENOENT") { node.warn('Command not found'); }
|
||||
else if (e.errno === "EACCES") { node.warn('Command not executable'); }
|
||||
else { node.error(e); }
|
||||
node.status({fill:"red",shape:"ring",text:"error"});
|
||||
node.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.redo === true) {
|
||||
var loop = setInterval( function() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-daemon",
|
||||
"version" : "0.0.17",
|
||||
"version" : "0.0.18",
|
||||
"description" : "A Node-RED node that runs and monitors a long running system command.",
|
||||
"dependencies" : {
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user