Maybe systemd.debug-shell
can help you to find the reason of the unexpected shutdown. Look at:
rpi ~$ zcat /usr/share/doc/systemd/README.Debian.gz | less
There is a section Debugging boot/shutdown problems. For shutdown problems, run
rpi ~$ sudo systemctl start debug-shell
In situations where the debug shell is not available, you can generate a
/shutdown-log.txt file instead:
1. Boot with these kernel command line options:
systemd.log_level=debug systemd.log_target=kmsg log_buf_len=1M
2. Save the following script as /lib/systemd/system-shutdown/debug.sh and make it executable:
#!/bin/sh
mount -o remount,rw /
dmesg > /shutdown-log.txt
mount -o remount,ro /
3. Reboot
update:
Giving some more details to use /shutdown-log.txt
: with specific command line options as shown above you can tell the kernel to execute a shell script at a very late time on shutdown. Edit cmdline.txt:
rpi ~$ sudo -e /boot/cmdline.txt
and append these parameters with a space between them. Don't insert a line break. The whole cmdline must be one line. Save and quit the editor:
systemd.log_level=debug systemd.log_target=kmsg log_buf_len=1M
Create the debug script and make the script executable. Start with:
rpi ~$ sudo -Es
You can copy an paste this block including the EOF
to your command line and execute it:
cat > /lib/systemd/system-shutdown/debug.sh <<EOF
#!/bin/sh
mount -o remount,rw /
dmesg > /shutdown-log.txt
mount -o remount,ro /
EOF
root@rpi ~# chmod u+x /lib/systemd/system-shutdown/debug.sh
root@rpi ~# exit
rpi ~$
Now you can reboot and afterwards you will find a file /shutdown-log.txt
. It may be a little bit difficult to find the shutdown messages because the kernel also logs its old startup messages. You can look at the timestamp or search for systemd-shutdown
. It may be also possible that there are important messages before systemd-shutdown
. For example here is the relevant snippet from my raspi:
[ 14.348539] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 14.348551] Bluetooth: BNEP filters: protocol multicast
[ 14.348568] Bluetooth: BNEP socket layer initialized
[ 921.128046] Bluetooth: hci0 sending frame failed (-49)
[ 923.621971] systemd-shutdow: 33 output lines suppressed due to ratelimiting
[ 923.802419] systemd-shutdown[1]: Sending SIGTERM to remaining processes...
[ 923.809468] systemd-journald[190]: Received SIGTERM from PID 1 (systemd-shutdow).
[ 923.888164] systemd-shutdown[1]: Sending SIGKILL to remaining processes...
You can add any command you want to the script. You may insert your temperature logging. For example I have appended the date to the log:
rpi ~$ cat /lib/systemd/system-shutdown/debug.sh
#!/bin/sh
mount -o remount,rw /
dmesg > /shutdown-log.txt
date >> /shutdown-log.txt
mount -o remount,ro /
Hope you can see something when the raspi gets stuck. It can be that it isn't even able to execute the script or simply doesn't shutdown. Don't forget to revert all this settings when you have finished debugging.