Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to suspend bees on battery power #302

Open
Atrate opened this issue Feb 20, 2025 · 1 comment
Open

Add option to suspend bees on battery power #302

Atrate opened this issue Feb 20, 2025 · 1 comment

Comments

@Atrate
Copy link

Atrate commented Feb 20, 2025

For laptops, it'd be useful if bees could automagically suspend itself when it detects that the laptop is running on battery power, returning to processing once AC power is back.

@Zygo
Copy link
Owner

Zygo commented Feb 28, 2025

Does something like this work?

cat <<RULES >> /etc/udev/rules.d/60-onbattery.rules
# Stop when AC power offline
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="0",RUN+="killall -STOP bees"
# Resume when AC power online
SUBSYSTEM=="power_supply",ENV{POWER_SUPPLY_ONLINE}=="1",RUN+="killall -CONT bees"
RULES

The above should stop bees from doing any processing while on battery, but keep the process resident in memory so it can resume immediately when AC power is restored.

It will also stop or start any random program that happens to be named bees. There's probably a better way to do that, e.g. freezer cgroup controls.

Variations:

  1. You can use USR1 instead of STOP, and USR2 instead of CONT, if you want bees to save its state files and release open files while on battery. While on battery, there will be a low rate of continuous IO while the hash table trickles out to disk. That will eventually stop, but it might take hours. It will take longer to transition to the suspended state than the STOP/CONT method.

  2. You can completely stop and start the service with systemctl, which will cause a large burst of IO when transitioning as the entire hash table will be saved and reloaded. It may repeat some work if you frequently transition to/from AC power.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants