Node-RED Self Restart

Is there a node red restart command available?

I have put a reboot command in an exec node which works well, but sometimes it maybe that node red requires a restart rather than the computer and I wondered if restart was available or was being considered? Obviously if I issue a node-red-stop through an exec node on the app I am unable to do anything further unless I VNC on to then start node red.

Can anybody advise please?

It depends what OS you are running on. On a Debian based linux such as Raspbian then the command
sudo systemctl restart nodered
should do it, assuming you have installed node red using the pi recommended method.

I think exec blocks calls to sudo as it’s a privilege escalation…

Can they be concatenated and called as a single call ?
node-red-stop && node-red-start

PR always welcome

That is not my experience. On one of my Pis I have a watchdog which runs sudo reboot in a watchdog flow.

If the machine is setup to require passwords on the use of sudo then it is necessary to disable the password request for that command using sudo visudo to invoke the sudoers editor so in the case of reboot I have

myusername ALL=(ALL) NOPASSWD: /sbin/reboot

Thank you I will try this.

Ia have on an exec node the same that works for me on command line, directly: sudo service nodered restart

Regards

I seem to recall that node-red-stop will of course stop node-red, however because node-red is not then running, the second command node-red-start is not actioned. (I found this out the hard way whilst 200 miles away from home!!).

Paul

looks like sudo service nodered restart is the winner then !

1 Like

Just to add - all of this presumes you are running on a Raspberry Pi or similar using the service scripts we provide. That is just one of many different ways that Node-RED can be run - so there will not be a one-size-fits-all restart command for Node-RED - it all depends on how its being run.

sudo service nodered restart may still work but it is not the correct way of doing it on recent Debian systems such as Raspbian and Ubuntu. That command was obsoleted when systemd became the standard way of doing it with Jessie (I believe) in 2015. Use instead

sudo systemctl restart nodered

I note that node-red-start also uses the service command, ideally this should be updated since at some point it will stop working, though admittedly it may not be for a long time.

Consider I just started again working with linux since one year ago… more than 20 years out of the game

This got me wondering how the service command still works on a systemd based OS. Running cat /usr/sbin/service it seems that it is a wrapper script converting the service command to the appropriate systemctl one.

Yes its a wrapper around various ways of doing it (on Linux), so is actually the most transportable way to do it. No need to "fix" it.

Good point, though I notice that node-red-start (on pi) does assume that the OS uses systemd. You are right however, there is nothing wrong with using the service command.

In case you want a flow - this works on a Pi and should work on any modern Linux (that uses systemd which is most of them).

[{"id":"384924bd.c7b6dc","type":"exec","z":"106a5b82.ef95a4","command":"sudo systemctl restart nrlive","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":873,"y":617,"wires":[["c8f2f6f1.370d08"],["c8f2f6f1.370d08"],["c8f2f6f1.370d08"]]},{"id":"5c9d8978.a36278","type":"inject","z":"106a5b82.ef95a4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":674,"y":617,"wires":[["384924bd.c7b6dc"]]},{"id":"c8f2f6f1.370d08","type":"debug","z":"106a5b82.ef95a4","name":"","active":true,"console":"false","complete":"false","x":1143,"y":617,"wires":[]},{"id":"46129a4f.b9ed64","type":"comment","z":"106a5b82.ef95a4","name":"** DANGER!: Restart the Node-Red service **","info":"","x":770,"y":580,"wires":[]},{"id":"85941f67.76613","type":"inject","z":"106a5b82.ef95a4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":673,"y":708,"wires":[["f5f9bc5a.5ab3f"]]},{"id":"f5f9bc5a.5ab3f","type":"exec","z":"106a5b82.ef95a4","command":"sudo reboot now","addpay":false,"append":"","useSpawn":"","name":"","x":842,"y":708,"wires":[["e5e0f45f.0287f8"],["e5e0f45f.0287f8"],["e5e0f45f.0287f8"]]},{"id":"e5e0f45f.0287f8","type":"debug","z":"106a5b82.ef95a4","name":"","active":false,"console":"false","complete":"false","x":1142,"y":708,"wires":[]},{"id":"5714af73.78418","type":"comment","z":"106a5b82.ef95a4","name":"** DANGER! Reboots the Pi running Node-Red, InfluxDB and MQTT **","info":"","x":847,"y":672,"wires":[]},{"id":"7e632c5f.0a5944","type":"comment","z":"106a5b82.ef95a4","name":"TODO: Remove service name and pull from settings instead","info":"","x":1160,"y":580,"wires":[]}]

It has a flow for restarting Node-RED and one for rebooting the Pi. Works fine assuming that sudo is configured not to ask for an additional password when running these commands.

1 Like

Looks good. I’ll give it a go, thanks

Sorry if this is seen as a necropost, but I generally daemonize my instances using PM2, which opens up the option of using an exec node and running the command "pm2 restart node-red". PM2 also does a good job of restarting the runtime on its own if it pukes.

PM2 is fairly resource heavy and not necessary if you are using systemd or similar on a Linux system. PM2 is good for test and development systems. Or possibly on Windows if not using the scheduler.

Hi,

Any idea how to do a node-red restart when you have it running in a Docker/Container ?

FYI - Using the exec node and sending "pwd"; it tells me I'm here - "/usr/src/node-red", however commands like "reboot" or "restart" or "sudo" are not found

2 Likes

Her I am using sudo systemctl restart nodered.
With an exec node on my first flow.

But it would be nice to have an option in the web server easy accessible . Like near the node red log on the left .
With a phone I think it would be the best place to put it .