How do I make changes to /proc/acpi/wakeup permanent?

Solution 1:

I ran into this problem again on Ubuntu 12.10. The suggestions from user MTS unfortunately also did not work for me. However, you can write a script to automatically set the usb properties in /proc/acpi/wakeup right before every suspend.

The solution is based on creating a suspend hook (based on this Archwiki article). Save the following as /usr/lib/pm-utils/sleep.d/45fixusbwakeup, and make sure to make it executable (chmod +x /usr/lib/pm-utils/sleep.d/45fixusbwakeup).

#!/bin/bash
case $1 in
    hibernate)
            echo "Going to suspend to disk!"
            ;;
    suspend)
            echo "Fixing acpi settings."
            for usb in `cat /proc/acpi/wakeup | grep USB | cut -f1`;
            do
                    state=`cat /proc/acpi/wakeup | grep $usb | cut -f3 | cut -d' ' -f1 | tr -d '*'`
                    echo "device = $usb, state = $state"
                    if [ "$state" == "enabled" ]
                    then
                            echo $usb > /proc/acpi/wakeup
                    fi
            done
            echo "Suspending to RAM."
            ;;
    thaw)
            echo "Suspend to disk is now over!"
            ;;
    resume)
            echo "We are now resuming."
            ;;
    *)
            echo "Somebody is callin me totally wrong."
            ;;
esac

What this does is change the status of every USB device that is currently enabled to disabled. If you only want to change specific USB devices, change the for loop in the script. For example to change only USB1 and USB3 change

for usb in `cat /proc/acpi/wakeup | grep USB | cut -f1`;

to

for usb in 'USB1' 'USB3';

Hopefully this helps someone else who has the same problem. This approach solved the issue for me.

Solution 2:

Perhaps http://forum.xbmc.org/showthread.php?tid=121158 will help?

This is what it says:

For those who are updating to the 3.2 kernel (which should be everyone due to the recent root exploit), you'll notice your USB wakeup is probably broken. They changed the default wakeup policy (http://www.spinics.net/lists/linux-usb/msg53661.html), so you'll need to make a couple of changes:

  • you no longer need to enable wakeup in /proc/acpi/wakeup, it's enabled by default
  • you need to enable wakeup for the USB hub in addition to the device in /sys/bus/usb/devices/*/power/wakeup

So, this:

echo USB1 > /proc/acpi/wakeup
echo enabled > /sys/bus/usb/devices/3-1/power/wakeup

Becomes:

echo enabled > /sys/bus/usb/devices/usb3/power/wakeup
echo enabled > /sys/bus/usb/devices/3-1/power/wakeup

Hopefully this saves others from troubleshooting the same problem.

Solution 3:

For Ubuntu 15+, you must use systemd instead of rc.local. You may google "Creating a systemd service" and follow the instructions, but note that redirecting output to /proc/acpi/wakeup is tricky. To get it to work correctly, you must do something like:

/bin/sh -c '/bin/echo XHC > /proc/acpi/wakeup'

Example output for the service file (e.g., /etc/systemd/system/suspendfix.service):

[Unit]
Description=fix to prevent system from waking immediately after suspend

[Service]
ExecStart=/bin/sh -c '/bin/echo XHC > /proc/acpi/wakeup'
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Or here in this gist

Solution 4:

The preferred way to do this is by creating a service with systemd.
Adding script in rc.local is the deprecated way.

  1. Create a script file wherever you wish. Ex: ~/Scripts/disable-devices-as-wakeup.sh.
#!/bin/bash

declare -a devices=("USB0 USB2 US12 US15") # <-- Add your entries here
for device in "${devices[@]}"; do
    if grep -qw ^$device.*enabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done
  1. Test it by executing it from the terminal.

  2. If everything is okay then let's make a service.

$ touch ~/Scripts/disable-devices-as-wakeup.service
$ chmod u+x ~/Scripts/disable-devices-as-wakeup.service

~/Scripts/disable-devices-as-wakeup.service -

[Unit]
Description=Disable devices as wakeup

[Service]
ExecStart=/home/username/Scripts/disable-devices-as-wakeup.sh
Type=oneshot

[Install]
WantedBy=multi-user.target
  1. Copy paste or move the service to /etc/systemd/system/.
$ sudo cp ~/Scripts/disable-devices-as-wakeup.service /etc/systemd/system/
  1. Enable the service.
$ systemctl enable disable-devices-as-wakeup.service
  1. Restart the OS and check the status.
$ systemctl status disable-devices-as-wakeup.service

Detailed explanation found on https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd