I have a new wireless keyboard and everytime I go to suspend/sleep mode, my PC immediately wakes up again. Obviously the keyboard is constantly sending commands to the USB receiver.
I found out how to disable it from waking my PC by disabling the USB port where the receiver is plugged in:
Now I want this command to be executed automatically on bootup. I’ve tried several guides. For example by creating a systemd service unit. When I follow this* guide, everything seems to work. When I start the service manually (as mentioned at the end of the guide) by doing systemctl start disable-usb.service the USB port gets successfully disabled. But when I reboot it is enabled again…
What am I doing wrong? Or is there any other solution?
PS: I also tried this** method, didn’t work either (USB port was also not disabled after reboot).
I also did that (I followed all the steps from the guide). I then have to enter my pw and the port gets successfully disabled, however, when I reboot it is enabled again.
These services are executed in parallel. This means a different service could revert this change. For example tlp or something like this.
So you should make sure, this service is started very late in the boot process. You might want check the journal at which time your service is started and what happened after that.
You instruct systemd with the After= keyword in the unit section of your service to start this service after other services.
I guess thats it. When I type journalctl -u disable-usb I see lots of the following entries:
-- Boot 02a639134a124c11834a7ff3daccfdcc --
Jan 26 07:00:52 test-s6 systemd[1]: Started Disable-USB.
Jan 26 07:00:52 test-s6 disable-usb.sh[651]: /usr/local/bin/disable-usb.sh: line 3: /sys/bus/usb/devices/2-6/power/wakeup: No such file or d>
Jan 26 07:00:52 test-s6 systemd[1]: disable-usb.service: Main process exited, code=exited, status=1/FAILURE
Jan 26 07:00:52 test-s6 systemd[1]: disable-usb.service: Failed with result 'exit-code'.
When I start the service manually I get
Jan 26 09:22:21 test-s6 systemd[1]: Starting Disable-USB...
Jan 26 09:22:21 test-s6 systemd[1]: disable-usb.service: Deactivated successfully.
Jan 26 09:22:21 test-s6 systemd[1]: Finished Disable-USB
It looks like the service runs too early that the folder is not even mounted yet.
How can I make it start last? How do I find out which was the last service started?
According to this, lightdm.service is started last on my system. So I added the line After=lightdm.service
in my disable-usb.service file in the [unit] section. However, when I restart and do systemd-analyze plot > ~/plot2.svg, the service is still started in the same position as before and not at the end.
I followed the guide from your link. Since I didn’t have a file called 50-wake-on-device.rules in the folder /etc/udev/rules.d/, I created it and put the following into it:
I think something is not entirely correct in this approach. If I run
sudo udevadm control --reload-rules
and then
cat /sys/bus/usb/devices/usb*/power/wakeup
Everything is disabled. However,
cat /sys/bus/usb/devices/2-6/power/wakeup
still returns enabled and the issue of an immediate wakeup still exists. So it obviously didn’t effect the 2-6 resource. I think I would have to edit the SUBSYSTEM=="usb", DRIVERS=="usb" part somehow…?