question

xsilvergs avatar image
xsilvergs asked

node-red exec node reboot

I've been using the Large-Image withe Node-Red for a long time now and previously been able to Reboot or Shutdown my RPi using and Exec node. For Reboot the command has been "reboot #" and "poweroff #" to shutdown.

I have just noticed that neither command now works with an Error: 126. Is there a new command? Is this a permissions thing?

It's all worked so well for so long I've only needed to do updates so perhaps missed some changes. Thanks for any info.

Node-RED
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

3 Answers
pcurtis avatar image
pcurtis answered ·

I have been using a similar technique running shutdown in a Node-RED Exec node and yes error 126 is a permission problem. One can get more information on errors by connecting all three outputs of the exec node to a debug node which then shows shows the error output stream.

The have not said what machine or OS version number you are using but I saw in an earlier post you have a Raspberry Pi 4 but not which version which makes a definitive diagnosis of the problem more difficult. I however expected and saw exactly the same problem with a Pi 4 rev 1.5 using shutdown when I changed from a Venus OS 2.82 to the new candidate version series 2.90 currently 2.90~24 which supports the Pi 4 much better so you may have done the same.

The cause in my case is that node-red no longer runs as root but runs under a new user nodered in Venus OS v2.90. This is much more secure as single mistake in an exec node command running as root could brick some machines.

Use of commands such as shutdown, poweroff and reboot depend on being run as root otherwise any user could shutdown a multi-user machine.

The solution does not seem to be as simple as just changing permissions, they have to actually be run by root. The underlying Linux distribution in the Venus OS is openembedded-core Dunfell. As the name implies it is optimised for embedded systems with minimal utilities so users who have used desktop distributions such as Debian and its derivatives Ubuntu and Mint, like me, find it very different. It uses BusyBox so some common commands have reduced functionality and many are missing. There is no sudo for example so the normal techniques to allow certain programs to run as root under sudo without asking for a password do not work.

I am still looking for a more elegant solution but I have currently resorted to a quick fix of having a program running under root every few seconds which checks for the presence of a file whose contents contain the command line and run it before deleting the file. This entails a delay which is acceptable, even desirable, for shutdown activities and allows them to be cancelled. I am currently using a cron job run every minute. I can give more details if anyone asks.

If anybody has found a more elegant solution to the problem I would really like to hear!

3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

jeroen avatar image jeroen ♦ commented ·

openembedded can build all kind of things, and Venus does build the non-busybox versions as well e.g. as optional packages. After setting up opkg, just run:

opkg install packagegroup-replace-busybox

sudo will be available by default in the large image as well in the next candidate version.

1 Like 1 ·
xsilvergs avatar image xsilvergs commented ·
@pcurtis thank you for such a complete reply, I am using a Pi4 and running 2.90~24.

I have just installed kwindrem 's shutdown script which now allows me to shutdown from the menu, is there a way use dBus to shutdown and reboot the Pi from node-red?

0 Likes 0 ·
Show more comments
xsilvergs avatar image
xsilvergs answered ·

For anyone finding this thread I have had great and simple succsses by installing and using the "node-red-contrib-bigssh" node, just add user as 'root' and 'reboot' as the command (without the inverted commas).

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Dirk-Jan Faber (Victron Energy) avatar image
Dirk-Jan Faber (Victron Energy) answered ·

I have described the most easy way to reboot the device from Node-RED on https://github.com/victronenergy/node-red-contrib-victron/wiki/Example-Flows#venus-reboot

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.