Parse specific text from payload in Node-Red?

Hi all,

I have a small task but it is a bit too tricky for me :slight_smile:

I am running a script from an EXEC Node that sometimes failes (once a day).
In these cases I have to find out the ID of this script (using ps -ef | grep python) manually and stop it with a KILL command and simply restart the Script via EXEC Node.
Now I would like to automatize this Auto-Kill and Auto-Restart

I have the ID already in this payload field, now the question is to get exactly this value into a variable

It always has to be the ID before the EVN.py script, but I do not yet know how to read this value.

Do you have a hint for me ?

BR
Gawan

Use a status node pointed at the exec node.

connect a debug (set to show complete message) - you will find the status value.

Then in a function node, if it starts pid: then split it on : and get the value from element [1]

I added the status-node like this:

image

now it seems that the Raspberry Pi is down and cannot be reached any longer. I have to tell my friend to reboot it :slight_smile:

um why?

You have created a loop

image

Start node-red with the --safe flag to fix it.


When I said

I did NOT mean "connected" - when you setup the status node you "point" it at a node to watch its status.

1 Like

You don't need the ID. If you send a message into the exec node with msg.kill set to true then it will kill the current process. For more information see the help text for the node.

1 Like

So this one specific EXEC node is always linked to one process ?

What if I trigger the node several times from different sources ?
Which one will be killed if I send a "msg.kill" ?

If you have several instances running at once from the same exec then I guess you will have to provide the PID in msg.pid. Are you running several instances in parallel? You will also have trouble picking up the PID from the status in that case. How will you know which one is the one giving the problem?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.