I have read thru the post about this topic, and I think I have followed all the suggestions. But like others, it doesn't seem to run the script before total shutdown. I can find it from time to time in the log, but regularly, I can't seem to figure it out.
Here is the log that I have. And the way I guess I know it has worked is this part of the the code shows in the log.
cvlc: no process found
feh: no process found
display: no process found
I attached the txt file.
But as you can see as the log goes on, it stops showing in the log and I don't get the final email that is in the code.
Code I am using currently.
#!/bin/bash # file: beforeShutdown.sh # # This script will be executed after Witty Pi receives shutdown command (GPIO-4 gets pulled down). # If you want to run your commands before turnning of your Raspberry Pi, you can place them here. # Raspberry Pi will not shutdown until all commands here are executed. # # Remarks: please use absolute path of the command, or it can not be found (by root user). # Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh. # /usr/bin/sleep 60 /usr/bin/killall feh /usr/bin/killall vlc /usr/bin/killall cvlc /usr/bin/killall display /usr/bin/trash-empty /usr/bin/sleep 60 python /home/pi/wittypi/wls.py /usr/bin/sleep 60 #cec-ctl --to 0 --standby
Thank you for your help.
My suggestion is to print out a message at the beginning of the beforeShutdown.sh script, which indicates the script is being executed.
As long as the shutdown is triggered by pulling down GPIO-4 (or scheduled shutdown), I do not see the possibility that beforeShutdown.sh script sometimes gets executed, while sometimes not. It always runs before actually shut down your Pi.
However, everytime Witty Pi's software shuts down your Pi, it will print this message in the log:
Halting all processes and then shutdown Raspberry Pi...
This behavior is defined in the do_shutdown function. In your log, all those shutdowns without the "no process found" information seems missing this message as well, which implies that your Pi crashed when trying to kill some processes and the shutdown didn't actually happen.
There should be a better way than using the killall command. If you put nothing in the beforeShutdown.sh, WittyPi's software will run "shutdown -h now", which also halt all processes before shutdown.