Shutdown/reboot(/power on) Raspberry Pi with pushbutton
Connect the LCD with I2C connector to Raspberry Pi and ensure you are able to communicate to it on address 0x27:
i2cdetect -y 1
- I2C must be enabled in raspiconfig *
Connect pushbutton to BCM GPIO pin 23 and ground then run:
sudo python pishutdown.py
If you have a service you wish to shutxown prior to the Pi rebooting or shutting down, edit the {ServiceNameHere} in both lines to reflect the desired service name.
call(['systemctl', 'stop', 'ServiceNameHere'], shell=False)
When button is pressed for less than 5 seconds, Pi reboots. If pressed for more than 5 seconds it shuts down. While shut down, if button is connected to BCM GPIO pin 23, then pressing the button powers on Pi.
sudo systemctl enable pishutdown.service
sudo systemctl start pishutdown
sudo systemctl stop pishutdown
sudo systemctl restart pishutdown
From the directroy you are running pishutdown.sh
cat pishutdown.log