Thursday, May 26, 2016

The new release of Ubuntu 16.04 is out along with it's many derivatives. With it comes new issues. One such issue that is harped about especially by Noah and Chris from the Linux Action Show is the annoying habit of Network Manager to loose it's WiFi connection when returning from sleep (suspend) or hibernate. I'm not sure what the exact issue is but I've come up with a simple workaround.

Systemd allows for actions to happen when a condition is met. So, all we have to do is tell systemd to restart Network Manager when the system comes back up. We can call this nm-sleep.service.



[Unit]
Description=Restore Network after sleep
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
User=root
ExecStart=systemctl restart NetworkManager
StandardOutput=syslog

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Store the file as 
/etc/systemd/system/nm-sleep.service
  then all you have to do is inform systemd about it with  
sudo systemctl enable nm-sleep 

Every time your system comes back to life the systemd will restart networking as if you booted your computer. This makes sense, especially with a laptop because your connection could easily change between sessions. You might boot your laptop at a coffee shop and then suspend it to go home, plug in your ethernet and it would pop up instantly (or nearly so). The actual fix should probably be in Network Manager itself but this works just fine. I've been using it since I installed a beta back in February and had completely forgot about the problem until my favorite show brought it up.