UPS
Previously I made a simple script to be used with apcupsd
to handle events depending on when the main power source went offline or online. The script I used have passed down for 8 years since I started using a UPS for my server. The script is used to shut down all unnecessary processes in order to reduce power usage, but mostly to ensure the security of the process states, by reducing the possibility for corruption. As the RAID is in software, it may break if power is cut short. The same is to start all processes that usually is booted.
However, the capabilities for the scripts is pretty limited, and there is close to no communication between them, hence when both runs at the same time (On battery for a couple of seconds, closing down takes minutes, so when off battery it will shut down and start processes all over the place, leaving them in an undetermined state).
My planned solution for this, and why I’m writing about this now, is a daemon running in the background, receiving input from the scripts on how to act. The daemon will then put the actions in a queue. However, if it finds out that the queue contains actions that is against a new action, it will remove the old action and maybe(depending on the current state) ignore the new one, as the state was changed.
Example: 10 shutdown actions was sent to the queue. After 3 actions has been processed (and one action in process), an another 10 start actions on the same processes is sent in, 6 of which will be removed from the queue while 4 will be kept because those have already stopped and will now be started.
This materialized into a small script that was created over the course of a couple of hours. It still has some more potential for improvements, but other than that it is free to use.