I have a python script (taken from the forums here) that reboots my RPI when a button is pressed.

It works great, no issues, except that it refuses to start automatically (either on boot, login, anything). I have tried various options listed here (rc.local, .bashrc, idit.d tab, systems, crontab) and nothing seems to work.

Is it something as simple as my script actually not being very good, and something in there is stopping it from working?


import RPi.GPIO as GPIO
import time
import os

def button_callback(channel):
    print("Button was pushed!")

GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def Restart(channel):
   os.system("sudo shutdown -r now")

GPIO.add_event_detect(16,GPIO.RISING,callback = Restart, bouncetime = 2000)

message = input()


1 Answer 1


At a guess the script is immediately terminated when run in the background because of the message = input() line. The script's input and output will not be set to the devices you expect (screen and keyboard).

Replace that line with an eternal while loop. Something like the following.

while True:

Your Answer

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

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