In all the Raspberry PLC Family products, the UPS has its own configuration file called rpishutdown and service named rpishutdown-service. The placement of both files can be consulted in the Section 15.3 of the Raspberry PLC UserGuide. To execute specific commands before finishing the Power Off process, you must follow the next steps:
- Create this path inside the /etc folder:
sudo mkdir -p rpishutdown/hooks/
- Inside this folder, create a file called pre-poweroff:
sudo nano pre-poweroff
The file type can be anyone you want (Bash Scripts, Python, C++, etc.) but the most important thing is that it must be called pre-poweroff without any extension (you must indicate the file type with the corresponding Shebang). The script execution time cannot surpass 6 seconds (aprox.), as it is the Raspberry’s Power Off period. Take into account that this code only can be things that do not depend on the external power supply, like creating a file or things directly related with the Raspberry. (Following this rule, you cannot do things such as enabling an output so it depends on the external power supply).
- Give the execution permissions to the file:
sudo chmod ugo+x pre-poweroff
Following these steps, the file must be executed before the Raspberry Power Off.