kdave / btrfsmaintenance

Scripts for btrfs maintenance tasks like periodic scrub, balance, trim or defrag on selected mountpoints or directories.
GNU General Public License v2.0
900 stars 79 forks source link

Wait AC Power #45

Open comio opened 6 years ago

comio commented 6 years ago

NOT TESTED Only for review and discussion purpose.

comio commented 6 years ago

@sten0, Can you review the proposed code. Can you attach output of find /sys/class/power_supply -name online?. Thanks.

luigi

sten0 commented 6 years ago

@comio No output. Linux-4.9.80 on Debian 9. /sys/class/power_supply/AC: symbolic link to ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/ACPI0003:00/power_supply/AC /sys/class/power_supply/BAT0: symbolic link to ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:08/PNP0C09:00/PNP0C0A:00/power_supply/BAT0

On the other hand, if [ -f /sys/class/power_supply/*/online ]; then echo 'We are online"; fi works

comio commented 6 years ago

@stem0 @kdave

we can backport this script from OpenRC:

on_ac_power

and use this implementation if on_ac_power command is not present. This will move all /proc/blablabla logic into an external command/function.

kdave commented 6 years ago

I'm not sure if the on_ac_power is generally available, so we'll need some fallback anyway, but systemd has /usr/lib/systemd/systemd-ac-power so we can cover most cases I think.

comio commented 6 years ago

this is the code of on_ac_power:

systemd:on_ac_power

it's almost the same.

kdave commented 6 years ago

So the way you implement it in https://github.com/kdave/btrfsmaintenance/pull/45/commits/14c44e9d6e9ccfe6be5bcae42fd4cfa80480f35e it will just wait for AC and if it does not show up, the task continues. Is this desired from the user's POV? Eg. should we make it more configurable: