In all industrial Raspberry Pi PLC controller Family products, the UPS has its own configuration file called rpishutdown and service named rpishutdown-service. The placement of both files can be found in Section 15.3 of the industrial Raspberry PLC User Guide. To execute specific commands before completing the Power Off process, you must follow the steps below:
- 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 type of file can be whatever 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 execution time of the script cannot exceed 6 seconds (aprox.), as this is the Power Off period of the Raspberry. Note that this code can only be for things that do not depend on the external power supply, such as creating a file or things directly related to 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 open source PLC Raspberry Pi shuts down.