How to stop NodeRED from inside a flow?

I need to run NodeRED in batch mode (headless) in a Docker container. Works perfect but I cannot terminate NodeRED anymore.

NodeRED ist started (as root) with

/usr/local/bin/node $NODE_OPTIONS node_modules/node-red/red.js --userDir /data $FLOWS &

I tried to kill NodeRED with the exec-Node and SIGTERM / SIGKILL. But this does not work.

How can the entire NodeRED process be stopped from a flow?

I don't know anything about docker - heard of it, but that's about it.

Sorry, but why do you need to STOP node-red?

But if you want to stop Node-Red, why not issue the command:

With suitable path in front of it.

I have a flow running and at the end of this flow NodeRED has to terminate by itself. There should not be any further command as node-red-stop to be performed from outside NodeRED

exec node at the end of things happening in the flow.

That enters the command and kills (more like stops) Node-red.

No, the exec node does not work. The parameters for the exec node are:


The global PID is set to the process ID of NodeRED at the beginning of the flow.

Well, it maybe doesn't work because it needs the sudo password.

I'm not an expert, but there is a way to get around that.
Then you can simply enter that command and it should work.

But I'm not an expert.

In the exec node you need to put this:
echo myPassword | sudo -S node-red-stop

Where myPassword is your actual password.

It works.

Just tested it.

The exec node cannot be used to kill processes it didn't originally spawn itself.

One approach will be to write a script that does the process kill, and then exec that script from Node-RED.

1 Like

Just to check though: Could you confirm that the way I said would work?
Sorry again just wanting to make sure what I think is correct.

Of course it would be a lot easier if the node-red-stop command was attributed to not need the password.

In this instance, no it would not work because they are running node-red directly, rather than running it as a service (which is what node-red-start/node-red-stop control).



Just mentioning then:

AFAIK, my system uses systemd and node-red auto-starts.

I got an exec node and put that trick in with my real password.

Connected an inject node to the exec node, and pressed it.
Node-red stopped.
Well, I got a message at the top of my screen: Lost connection to server.
So I guess it stopped.

[{"id":"260ff9050f0901f0","type":"exec","z":"0918ee609bf69fc7","command":"echo \"my real password\" | sudo -S node-red-stop","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":470,"y":3660,"wires":[[],[],[]]},{"id":"6f621bb4c69c4357","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":3660,"wires":[["260ff9050f0901f0"]]}]

I am executing NodeRed as root (so I don't need sudo) and this does not work :frowning:

What is node-red-stop? I cannot find anything about this command. Maybe a RPI system script to start/stop NodeRED. But not available in my Docker environment.

Sorry @wolfred .... My reading skills are failing.

This is not my week for getting things right.

Solved it. There is a node exit to exlicity stop NodeRED: node-red-contrib-exit (node) - Node-RED.

This works like charm.

1 Like

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