Advertisement
CTpaHHoe

systemd power events

Sep 25th, 2022
1,251
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.06 KB | Source Code | 1 0
  1. ###############################
  2. ~ cat /etc/udev/rules.d/85-powertargets.rules
  3. SUBSYSTEM=="power_supply", KERNEL=="AC", ATTR{online}=="0", RUN+="/usr/sbin/systemctl start battery.target"
  4. SUBSYSTEM=="power_supply", KERNEL=="AC", ATTR{online}=="1", RUN+="/usr/sbin/systemctl start ac.target"
  5.  
  6. ###############################
  7. ~  cat /etc/systemd/system/ac.target
  8. [Unit]
  9. Description=On AC power
  10. DefaultDependencies=no
  11. StopWhenUnneeded=yes
  12.  
  13. ###############################
  14. ~ cat /etc/systemd/system/battery.target
  15. [Unit]
  16. Description=On battery power
  17. DefaultDependencies=no
  18. StopWhenUnneeded=yes
  19.  
  20. ###############################
  21. ~ cat /etc/systemd/system/powerdown.service
  22. # /etc/systemd/system/powerdown.service
  23. [Unit]
  24. Description=Laptop battery savings
  25.  
  26. [Service]
  27. Type=oneshot
  28. ExecStart=/usr/local/bin/powerdown
  29.  
  30. [Install]
  31. WantedBy=battery.target
  32.  
  33. ###############################
  34. ~ cat /etc/systemd/system/powerup.service
  35. [Unit]
  36. Description=Laptop battery savings
  37.  
  38. [Service]
  39. Type=oneshot
  40. ExecStart=/usr/local/bin/powerup
  41.  
  42. [Install]
  43. WantedBy=ac.target
Tags: Power systemd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement