Skip to content

Instantly share code, notes, and snippets.

@norrs
Created October 10, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norrs/ac102727be5ae10d0628dd169e68cf04 to your computer and use it in GitHub Desktop.
Save norrs/ac102727be5ae10d0628dd169e68cf04 to your computer and use it in GitHub Desktop.
systemctl cat --user git-sync-powersavehelper
# /home/norangshol/.config/systemd/user/git-sync-powersavehelper.service
[Unit]
Description = Disable and Enable git-sync depending on AC power
ReloadPropagatedFrom = sys-susbsystem-power_supply-main_AC.device
[Service]
ExecStart = /usr/bin/env git-sync-powersavehelper
ExecReload = /usr/bin/env git-sync-powersavehelper
RemainAfterExit=true
[Install]
WantedBy = sys-subsystem-power-supply-main_AC.device
norangshol@enceladus:~$ cat ~/.local/bin/git-sync-powersavehelper
#!/usr/bin/env sh
if /lib/systemd/systemd-ac-power ; then
echo "Power On: $(date)"
else
echo "Battery On: $(date)"
fi
@norrs
Copy link
Author

norrs commented Oct 10, 2018

root@enceladus:~# systemctl list-units --type=device | grep -i power_sup
sys-devices-LNXSYSTM:00-LNXSYBUS:00-PNP0A08:00-device:19-PNP0C09:00-ACPI0003:00-power_supply-AC.device loaded active plugged /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:19/PNP0C09:00/ACPI0003:00/power_supply/AC
sys-subsystem-power_supply-main_AC.device loaded active plugged /sys/subsystem/power_supply/main_AC

@norrs
Copy link
Author

norrs commented Oct 10, 2018

$ systemd-analyze verify --user git-sync-powersavehelper.service
norangshol@enceladus:~$ echo $?
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment