1

I've been facing this issue for a long time and I haven't been able to find a working solution for it. I've found a few different posts online of people having the same issue but none of the solutions have worked for me.

I'll give you some info about how the Pi is running so that you may have a better understanding of what could be causing the issue.

  • I have a big group of Raspberry Pi's all networked together via Ethernet (about 13 or so in total).
  • All of them are running a Python script that runs in rc.local.
  • The majority of them are using the GPIO pins to control different things.
  • Raspberry Pi 3 running Raspbian

I am running a game using them and they all control different elements of the game. When the game is over, we had just been turning off the power to the Pi's and then turning them back on to restart them when needed. (We were use to using Arduinos previously and they had no issue with this (knowledge was limited)). But to stop the Pi's from corrupting, we want to send a command to shut them down at the end of the game so we can safely turn them off.

The issue is, whenever we send the command, they all go to shutdown, but then they reboot and turn back on, which obviously prevents us from safely turning them off.

I've tried a few different things in the python script but they all seem to have the same result. Previously I've tried

from subprocess import call
call("sudo nohup shutdown -h now", shell=True)

Currently I'm trying

os.system("sudo shutdown -h now")

But is still restarts. If I run the command from the terminal on the pi it will shutdown correctly, but running it from the python script from rc.local will make it reboot.

Does anyone have any ideas for what the issue may be and any potential solutions?

Update infos from comments:
I understand you can't turn off the power to the pi, I just wanted to shut it down so it was safe to turn the power off. We are more or less using them as an arduino and I did read about the read-only option earlier. It might be a good work around, but ideally I'd love to find out the actual cause of the issue. I am not running the latest version, the game has been installed for about a year and has no internet access to be able to update them. They are running 4.14.98, however I don't really believe the version to be issue as this isn't an issue on all Pi's running that version.

I've tried testing the shutdown code on a Pi (same version) at home only networked to my PC and I can't seem to replicate the issue. It shuts down perfectly everytime... So perhaps the reboot is due to a voltage drop or something when it shuts down which causes it to reboot? I don't know, but it would seem weird for all 13 of them to have the same issue when they are all powered seperately. Or perhaps the network cable is somehow affecting them. I'm at a loss, I was googling for almost 8 hours today to find an answer.

11
  • 1
    have you tried sudo poweroff instead - shouldn't make a difference, but try it Nov 2, 2019 at 1:41
  • Usually a Pi is powered on as long as there is power physically connected. The shutdown or poweroff commands will only stop the operating system from running, not physically power off the Pi. There are some hardware ways around this, such as shop.pimoroni.com/products/onoff-shim.
    – Fred
    Nov 2, 2019 at 9:41
  • Based on your description though, if you are wanting to run your Pis like an arduino, you could also look into a read-only file system, e.g. raspberrypi.org/forums/viewtopic.php?t=161416. In this instance the risk of corruption is severely reduced as the Pi will only ever read from the SD card, and not write.
    – Fred
    Nov 2, 2019 at 9:45
  • 1
    Are you using the latest Raspbian Buster fully updated?
    – CoderMike
    Nov 2, 2019 at 11:01
  • I understand you can't turn off the power to the pi, I just wanted to shut it down so it was safe to turn the power off. We are more or less using them as an arduino and I did read about the read-only option earlier. It might be a good work around, but ideally I'd love to find out the actual cause of the issue. I am not running the latest version, the game has been installed for about a year and has no internet access to be able to update them. They are running 4.14.98, however I don't really believe the version to be issue as this isn't an issue on all Pi's running that version. Nov 2, 2019 at 11:13

1 Answer 1

0

I had success using exactly what you posted:

from subprocess import call call("sudo nohup shutdown -h now", shell=True)

Hadrware: Pi 4.

OS: Raspian (most recent)

Python: 3.9.2

Other forums are not of much help either https://forums.raspberrypi.com/viewtopic.php?t=133665 , BUT there is something to try here https://learn.sparkfun.com/tutorials/raspberry-pi-safe-reboot-and-shutdown-button/all and here https://www.ridgesolutions.ie/index.php/2013/02/22/raspberry-pi-restart-shutdown-your-pi-from-python-code/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.