Skip to content

Instantly share code, notes, and snippets.

@neuthral
Last active May 16, 2024 08:35
Show Gist options
  • Save neuthral/e6bf6770b8aaa98434686a78c5bcfbfb to your computer and use it in GitHub Desktop.
Save neuthral/e6bf6770b8aaa98434686a78c5bcfbfb to your computer and use it in GitHub Desktop.
powertop custom startup service

on ubuntu 22.04 i need to have powertop run on startup as a service as powertop --auto-tune to set all devices on "good" power saving status but this also disables mouse and keyboard so its very annoying to have to wake up the device before using it again after 5 seconds

powertune.sh script sets all devices on powersave except usb

edit powertop.service to start yourt script in the correct location in ExecStart=(path to script) copy the service to: /etc/systemd/system/powertop.service

systemctl daemon-reload systemctl enable powertop.service

also look for help here: https://askubuntu.com/questions/112705/how-do-i-make-powertop-changes-permanent

## /etc/systemd/system/powertop.service
[Unit]
Description=Powertop service to tune powersaving stuff to good
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=
ExecStart=/home/user/configs/powertop/powertune.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
powertop --auto-tune
HIDDEVICES=$(ls /sys/bus/usb/drivers/usbhid | grep -oE '^[0-9]+-[0-9\.]+' | sort -u)
for i in $HIDDEVICES; do
echo -n "Enabling " | cat - /sys/bus/usb/devices/$i/product
echo 'on' > /sys/bus/usb/devices/$i/power/control
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment