How to re-enable bluetooth after system resume

Late 2018 (modified March 11, 2021)

I share a problem with a lot of people: The bluetooth on my laptop stops working after awakening from suspend state and sometimes doesn’t even activate at boot.

The problem is, that firmware needs to be uploaded to the device, and this sometimes failes during the boot/wakeup process.

One solution is as simple as unsatisfying:

Re-enable bluetooth

Once the machine is fully booted/resumed, it is sufficient to reload the btusb module to reupload the firmware to the device and thereby re-enabling bluetooth services:

#!/bin/bash
notify-send "Restarting Bluetooth..."
sleep 2
sudo /usr/bin/rmmod btusb
sleep 3 
sudo /usr/bin/modprobe btusb

Just execute ${HOME}/bin/restart_bluetooth.sh at the command line, after a suspended session is resumed.

It would be nice to automate that.

Enable a systemd instance for user

To enable a systemd instance that respects services and targets defined in ${HOME}/.config/systemd/user, execute

sudo loginctl enable-linger $USER

The extra-instance will be started at boot, to the best of my knowledge – I don’t know what service to restart to enable this behaviour without a reboot of the system.

A service definition to run after suspend

[Unit]
Description=User resume actions
After=suspend.target

[Service]
User=%I
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/home/%u/bin/restart_bluetooth.sh

[Install]
WantedBy=suspend.target