Save power on battery with udev


I just wanted to share a tip, as I was optimizing power usage on my Linux laptop and I’ve decided to pause syncthing on battery.

To do so I’ve created /etc/udev/rules.d/61-powersave.rules with the following content (append if already exists):

SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/bin/killall -STOP syncthing"
SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/bin/killall -CONT syncthing"

Reload udev with:

udevadm control --reload-rules

Works fine on Fedora 22, but should work on any system with udev.