I know this is an old sticky, but this approach may help others. I run Batocera on my Pi3, but you should be able to configure this on any other distribution.
This assume a momentary push button to shutdown and then if desired, startup the Pi.
1. Connect your push button across physical pins 6 and 5 on the Pi GPIO as shown (credit to https://gilyes.com/pi-shutdown-button/)
2. Edit your /boot/config.txt and add this line (check no others load the overlay):
dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up
3. Install or run triggerhappy daemon. This will handle the KEYPOWER event that the above overlay generates. If you have batocera installed, Triggerhappy (thd) is running by default with instructions to configure your own multimedia.conf to handle the KEYPOWER event (that is - you don't need to do anymore. Batocera will startup and shutdown when you press your button):
https://github.com/wertarbyte/triggerhappy
4. Add the following to your multimedia.conf file
KEY_POWER 1 /sbin/shutdown -h now
This assume a momentary push button to shutdown and then if desired, startup the Pi.
1. Connect your push button across physical pins 6 and 5 on the Pi GPIO as shown (credit to https://gilyes.com/pi-shutdown-button/)
2. Edit your /boot/config.txt and add this line (check no others load the overlay):
dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up
3. Install or run triggerhappy daemon. This will handle the KEYPOWER event that the above overlay generates. If you have batocera installed, Triggerhappy (thd) is running by default with instructions to configure your own multimedia.conf to handle the KEYPOWER event (that is - you don't need to do anymore. Batocera will startup and shutdown when you press your button):
https://github.com/wertarbyte/triggerhappy
4. Add the following to your multimedia.conf file
KEY_POWER 1 /sbin/shutdown -h now