# How to reboot raspi from NR

**URL:** <https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254>\
**Category:** General\
**Tags:** raspberry-pi\
**Created:** [25 September 2024 12:44 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254 "2024-09-25T12:44:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![duaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duaw/32/20970_2.png) [@duaw](https://discourse.nodered.org/u/duaw)\
**Post date:** [25 September 2024 12:44 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/1 "2024-09-25T12:44:42Z")

</div>

Hi!  
I have a raspi (Raspberry Pi 3 Model B Plus Rev 1.3, Debian Linux 12 says webmin) in my greenhouse running NR 4 locally. The pi is on my network using wifi. From time to time the pi loses the connection. I also have shellies in the greenhouse, they just work all the time.  
I could (and should) figure out why the wifi connection drops occasionally with the pi (but not with the shellies) but in the meantime I could just restart the raspi.  
I am not that of a linux guy, there seems nothing related to be in the forum.

- NR can ping the remote server, this may fail
- NR can detect the change of availability of the remote MQTT server, how does one detect that?
- NR should gracefully reboot the pi - how can this be done? Doesn't that need root/admin power?  
Any idea how to find out why wifi drops? (btw: I tried powerline/cable, this was too flaky)  
Thanks in advance!  
Cheers, Uwe

---

<div class="post-metadata">

**Author:** ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)\
**Post date:** [25 September 2024 13:07 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/2 "2024-09-25T13:07:32Z")

</div>

You can try it with the exec node.

---

<div class="post-metadata">

**Author:** ![duaw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/duaw/32/20970_2.png) [@duaw](https://discourse.nodered.org/u/duaw)\
**Post date:** [25 September 2024 15:22 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/3 "2024-09-25T15:22:26Z")

</div>

sudo reboot in the exec node did it.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [25 September 2024 15:25 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/4 "2024-09-25T15:25:31Z")

</div>

The Raspberry Pi has a hardware watchdog which can be setup to reboot the Pi if network access is lost or other services are unavailable.

There is a write-up at [https://diode.io/blog/running-forever-with-the-raspberry-pi-hardware-watchdog](https://diode.io/blog/running-forever-with-the-raspberry-pi-hardware-watchdog)

---

<div class="post-metadata">

**Author:** ![DiverRich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diverrich/32/64523_2.png) [@DiverRich](https://discourse.nodered.org/u/DiverRich)\
**Post date:** [25 September 2024 18:26 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/5 "2024-09-25T18:26:23Z")

</div>

Just attach whatever you need to trigger it to this node.

```auto
[{"id":"5beb96fc1c9e261b","type":"exec","z":"edce5f4c305a1484","g":"ed28e8ce3fc4343a","command":"node-red-restart","addpay":"payload","append":"","useSpawn":"true","timer":"","winHide":false,"oldrc":false,"name":"","x":800,"y":760,"wires":[["45e59a0a450bfdd5"],["45e59a0a450bfdd5"],["45e59a0a450bfdd5"]]}]

```

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [25 September 2024 18:42 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/6 "2024-09-25T18:42:36Z")

</div>

If you try it with other Linux distributions you will likely need to do:

```auto
sudo visudo
# add after the last line of the file (#includedir /etc/sudoers.d):
YourUserName ALL=(ALL) NOPASSWD:ALL

```

The Pi has come with this as the default from the beginning unless it has been changed in the newer versions. Generally a very bad idea to have this set on a system that is used with the external Internet.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2024 09:15 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/7 "2024-09-26T09:15:58Z")

</div>

> [@wb666greene](#):
>
> `YourUserName ALL=(ALL) NOPASSWD:ALL`

Don't do that, that allows node red (or any user) to run sudo with any command, without entering a password. Limit it to only the user and command that you want to allow, so if the user is, for example, pi then use  
`pi ALL=(ALL) NOPASSWD: /sbin/reboot`

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [26 September 2024 17:24 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/8 "2024-09-26T17:24:42Z")

</div>

That would seem to be a much better option, but the Raspbian OS has come setup as I'd described by default pretty much since day one. Maybe they have changed it in newer releases for the more powerful systems that people might use as actual desktops, but I've not done anything with a Pi for a couple of years now.

Can you add multiple commands to the list or add multiple lines? Being able to Power Down as well as reboot is useful for headless systems.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2024 20:10 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/9 "2024-09-26T20:10:39Z")

</div>

> [@wb666greene](#):
>
> Can you add multiple commands to the list or add multiple lines?

Both. You can add multiple lines, and/or allow multiple commands  
`pi ALL=(ALL) NOPASSWD: /sbin/reboot, sbin/shutdown`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 October 2024 20:11 UTC](https://discourse.nodered.org/t/how-to-reboot-raspi-from-nr/91254/10 "2024-10-10T20:11:22Z")

</div>

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