[Unit]
Description=piNail2 E-Nail Temperature Controller
After=network.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi/piNail2
ExecStart=/usr/bin/python3 app.py
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal

# Safety: if the service crashes, GPIO cleanup happens in the app.
# But as an extra safety net, run a one-shot relay-off on stop.
ExecStopPost=/bin/bash -c 'echo "2" > /sys/class/gpio/unexport 2>/dev/null || true'

[Install]
WantedBy=multi-user.target
