I am running a Rpi 3b+ headless, mostly for Pi-Hole now. Nothing external connected, not even a monitor, a mouse or a keyboard.
But because it runs PiHole, and my DHCP clients use it as domain server, it's crucial in my setup.
But it keeps shutting down randomly.
Its power supply is 5V 2500mA. This shouldn't be the issue.
I can only think of my shutdown button script. It is registered as init.d script, and listens to GPIO
#!/usr/bin/env python
import RPi.GPIO as GPIO
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(3, GPIO.FALLING)
subprocess.call(['/usr/local/bin/cleanup.sh'], shell=True)
subprocess.call(['shutdown', '-h', 'now'], shell=False)
Don't remember where I got this from (for due credits). Could possibly the GPIO.FALLING occur for different reasons other than me pushing the connected button? Is there maybe some safer way for me to do this?
EDIT: Just found this log also:
Mar 23 11:33:10 raspberrypi listen-for-shutdown.sh[514]: /usr/local/bin/listen-for-shutdown.py:8: RuntimeWarning: A physical pull up resistor is fitted on this channel!
Mar 23 11:33:10 raspberrypi listen-for-shutdown.sh[514]: GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Or any other ideas? Looking at the syslog, there's nothing to see other than logs of this script before shutting down. You can see I call a cleanup.sh
script here, and there's a log of it out of the blue before shutting down, so this means to me this GPIO stuff triggers the shutdown:
#!/bin/bash
echo "Running cleanup script..."
#does some other cleanup before shutdown
The logs show firewall stuff and out of the blue the cleanup script log:
Mar 23 11:32:02 raspberrypi kernel: [222378.037634] [UFW BLOCK] IN=eth0 OUT= MAC=<MAC> SRC=10.1.1.1 DST=10.1.1.53 LEN=357 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=1900 DPT=48807 LEN=337
Mar 23 11:32:02 raspberrypi kernel: [222378.141760] [UFW BLOCK] IN=eth0 OUT= MAC=<MAC> SRC=10.1.1.1 DST=10.1.1.53 LEN=351 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=1900 DPT=48807 LEN=331
Mar 23 11:32:47 raspberrypi listen-for-shutdown.sh[463]: Running cleanup script...
Mar 23 11:32:50 raspberrypi systemd[1]: Stopped target Timers.
Mar 23 11:32:50 raspberrypi systemd[1]: systemd-tmpfiles-clean.timer: Succeeded.
The listen-for-shutdown.sh
is at /etc/init.d/listen-for-shutdown.sh
, and triggers the above python script:
case "$1" in
start)
echo "Starting listen-for-shutdown.py"
/usr/local/bin/listen-for-shutdown.py &
;;
stop)
echo "Stopping listen-for-shutdown.py"
pkill -f /usr/local/bin/listen-for-shutdown.py
;;
*)
echo "Usage: /etc/init.d/listen-for-shutdown.sh {start|stop}"
exit 1
;;
esac
exit 0