My computer sometimes complained about inhibitors when trying to sleep. This was fixed by editing '/etc/systemd/logind.conf' to ignore inhibitors on suspend. Now it enters sleep instantly, no hassle what-so-ever.
As always, read it through before use, usage is described in the script. You will have to modify the usbdevice string prior to running it, or it may have unforeseen consequences. No warranties of any kind, expressed and/or implied.
Enjoy!
Code: Select all
#!/bin/bash
#
# Disables a USB device during sleep. Here a wireless mouse. Keyboard wakes the computer.
#
# USAGE:
#
# On Debian, put it in /lib/systemd/system-sleep/ as executable
#
echo -e "\nUncomment or remove this line when you have modified the "usbdevice" line below to reflect the device you want to control.\n" && exit 1
usbdevice="045e:07b2 Microsoft Corp."
distribution=`lsb_release -i | awk '{print $3}'`
if [ "$distribution" != "Debian" ]; then echo "This script has been tested on Debian only. You seem to be running on $distribution. You will have to verify correct behavior yourself. I will now exit."; exit 1; fi
# Simple logging of events (for debugging)
log=/tmp/SLEEP-LOG.txt
DATE=`date '+%Y-%m-%d %H:%M:%S'`
#touch $log
# Find a specific USB device
usbstring=`lsusb|grep $usbdevice`
bus=`echo $usbstring | awk '{print $2+0}'`
device=`echo $usbstring | awk '{print $4+0}'`
case $1 in
pre)
echo $bus:$device | tee /sys/bus/usb/drivers/usb/unbind
echo "$DATE - $1: Disabling mouse [$bus:$device] while going to $2" >> $log
;;
post)
echo $bus:$device | tee /sys/bus/usb/drivers/usb/bind
echo "$DATE - $1 Enabling mouse [$bus:$device] after $2" >> $log
;;
esac