I followed the project described in *[Raspberry Pi Shutdown Switch – Safely Turning off the Pi][1]*, but set pin 17 to be internally pulled up. Then connect the wires like the above project, but leave out any resistors and add the following Python script in `/etc/rc.local`:

`python shutdown_button.py`

### File shutdown_button.py

    import RPi.GPIO as GPIO
    import time
    import os
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
    while True:
        print GPIO.input(17)
        if (GPIO.input(17) == False):
            os.system("sudo shutdown -h now")
            break
        time.sleep(1)

  [1]: http://www.3cc.org/blog/2013/01/raspberry-pi-shutdown-switch-safely-turning-off-the-pi/