Linux and sleep mode wakeup

I just recently battled a long time to get my Windows machine to sleep properly. That is, to automatically go to sleep mode after a timeout, not wake up from sleep mode from useless events like keyboard and mouse, and recover from sleep mode successfully.

In Linux, pretty much everything worked out of the box, even with exotic-ish hardware (Apple Mac Mini), except for not waking up from useless events.

Preventing automatic wakeup from useless events

So I had the issue that my Linux desktop was waking up when I touched the mouse or keyboard, this is not a good thing in general, and especially not for me since I have several cats walking around all the time.

I just recently battled for quite a while with Windows to get it to work, and it was somewhat difficult to find useful and relevant information. It was a nice reminder of how great the Linux community is when I had to do the same thing in Linux.

It took a single Google query to find all the data I needed (from the first result), and here is the script that will disable waking up from all events except the power button:

for dev in $(cat /proc/acpi/wakeup | grep enabled | cut -f1); do echo $dev > /proc/acpi/wakeup; done

(Run it as root, su -, or sudo -i)

What it does, is list all the enabled wakeup devices (cat /proc/acpi/wakeup | grep enabled), and loop through the items on the first column, then echo the name of the device back to the API to toggle their state to disabled.

They say some devices' state can be reset after a reboot, so it could be useful to put that line in /etc/rc.local or similar file on your system.