Run a service to start and safe shutdown Pi boards using a momentary push-button switch.
Everytime when you need to shutdown headless Pi boards, either you need to plugin a monitor or SSH into the Pi. By connecting a pushbutton across GPIO and by running a service, now you can safe shutdown and restart Pi boards.
1. Clone the git:
git clone https://github.com/shivasiddharth/pi-shut
2. Run the installer.
sudo chmod +x /home/pi/pi-shut/installer.sh
sudo /home/pi/pi-shut/installer.sh
3. Wire the Pi as per the diagram.
4. Start the shutdown service.
sudo systemctl start on-off-pushbutton.service
Now, you have the service to safe shutdown and restart Pi working.
Source: Service to Safe Shutdown Headless Raspberry Pi Boards