axeleroy
-
Posts
26 -
Joined
-
Last visited
Reputation Activity
-
axeleroy reacted to Chris Bognar in Script to check the power status, and shutdown if battery is low!
If anyone is interested, I've created a shell script that can be run with cron to check A/C and battery status, and do a graceful shutdown when a battery threshold is met. It also logs power outages, battery drain when off A/C, and when it posts a shutdown (if any). This is a simple script, nothing fancy, but works for me. It has a granularity of one minute (cron is limited to one minute intervals), but I've been able to keep the system up on heavy load for 4-5 minutes before the script generates a shutdown on low battery.
The script is generous -- it waits for 916mV or less before a shut-down. This value was provided by the KOBOL team on their Wiki as the recommended shutdown threshold for the battery, but can be changed via the script. You can comment out any file-logging lines, or change the file location, also from within the script. I've heavily commented it, should be pretty easy to follow.
Copy the script below into a file named whatever you choose, place it where you want to run it, and cron it to get it going. It should only create disk writes when the power is out or when shutting down from battery drain on no A/C (a few lines once per minute), and will create no disk writes if you comment out the logging.
Let me know how it works for you, if you use it. I've been testing it for the past couple of days, and it's worked as intended. I'm always open to code tips, and I'm still learning, so any advice is appreciated.
-
axeleroy got a reaction from gprovost in Does anyone actually have a stable system?
My Helios is stable, running LUKS, MergerFS, SnapRAID, OMV and 9 Docker containers from SD Card and with 3 HDDs.
Although in order to get a stable system I had to lock CPU frequency at 1.2GHz, otherwise CPU intensive tasks (like SnapRAID's scrub) would cause my Helios to reboot.
================================================================================ = System information ================================================================================ Linux helios64 5.10.21-rockchip64 #21.02.3 SMP PREEMPT Mon Mar 8 01:05:08 UTC 2021 aarch64 GNU/Linux ================================================================================ = Uptime ================================================================================ 12:25:17 up 8 days, 1:18, 0 users, load average: 0.01, 0.10, 0.15 ================================================================================ = openmediavault information ================================================================================ Release: 5.6.2-1 Codename: Usul ================================================================================ = openmediavault plugins ================================================================================ ii openmediavault-backup 5.2.4 all backup plugin for OpenMediaVault. ii openmediavault-flashmemory 5.0.8 all folder2ram plugin for OpenMediaVault ii openmediavault-keyring 1.0 all GnuPG archive keys of the OpenMediaVault archive ii openmediavault-luksencryption 5.0.2 all OpenMediaVault LUKS encryption plugin ii openmediavault-minidlna 5.0.5 all OpenMediaVault miniDLNA (DLNA server) plugin ii openmediavault-omvextrasorg 5.6 all OMV-Extras.org Package Repositories for OpenMediaVault ii openmediavault-snapraid 5.0.7 all snapraid plugin for OpenMediaVault. ii openmediavault-unionfilesystems 5.1.2 all Union filesystems plugin for OpenMediaVault. ii openmediavault-wol 3.4.2 all OpenMediaVault WOL plugin
PS: don't mind the uptime, I had to reboot to apply an update. Otherwise no problem since mid-February.