Cool stuff for Raspberry Pi, Arduino and all electronics hobby projects
Notifications
Clear all

[Solved / Archived] beforeShutdown.sh Not working. I know, I know.

2 Posts
2 Users
0 Likes
91 Views
(@chip-thomas)
Posts: 1
New Member Customer
Topic starter
 

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.

 

 
Posted : 16/08/2024 11:24 pm
Topic Tags
(@admin)
Posts: 432
Member Admin
 

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.

 
Posted : 17/08/2024 10:25 am
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.