no wifi after suspend on 15.04 [duplicate]

My wifi is not working after suspend on 15.04. I can click my way to success on the wifi icon in the menu bar (and the enable wifi option), but I want to use scripts to automate the procedure. Here is my attempt

1) create executable bash script /etc/pm/sleep.d/10_resume_wifi with the contents

#!/bin/sh
  case "$1" in
   hibernate|suspend) ;;
   thaw|resume)
      nmcli r wifi off && nmcli r wifi on ;;
esac

2) create executable file /etc/system.d/system/wifi-resume.service with contents

[Unit]
Description=Restart wifi after waking up
After=suspend.target

[Service]
Type=simple
ExecStart=-/etc/pm/sleep.d/10_resume_wifi

[Install]
WantedBy=suspend.target

and run sudo systemctl enable wifi-resume.service

This is not working, and I get the following lines from dmesg after resuming from suspend

[11168.786104] cfg80211: World regulatory domain updated:
[11168.786111] cfg80211:  DFS Master region: unset
[11168.786113] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[11168.786119] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm), (N/A)
[11168.786124] cfg80211:   (2457000 KHz - 2482000 KHz @ 40000 KHz), (300 mBi, 2000 mBm), (N/A)
[11168.786128] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm), (N/A)
[11168.786133] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm), (N/A)
[11168.786137] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm), (N/A)
[11168.968257] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[11169.004818] ata3: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
[11169.006600] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[11169.009053] ata3.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[11169.009061] ata3.00: configured for UDMA/100
[11169.200846] firewire_core 0000:04:00.0: rediscovered device fw0
[11171.088442] ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
[11171.089310] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[11171.090296] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
[11171.090469] ata1.00: configured for UDMA/100
[11171.615861] ERROR @wl_cfg80211_scan : WLC_SCAN error (-22)

After clicking my way to wifi, I get slightly different output from dmesg

[11331.635796] cfg80211: Calling CRDA for country: US
[11331.639456] cfg80211: Regulatory domain changed to country: US
[11331.639465] cfg80211:  DFS Master region: FCC

Any suggestions for why the script-based approach is not working? I am new at this, so there are likely several errors. Thanks in advance!


Solution 1:

After a little more digging, I found a single script (posted here) that connects my computer to wifi after suspend. In short, I created the executable script /etc/systemd/system/wifi-resume.service with the following contents:

[Unit]
Description=Local system resume actions
After=suspend.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target

and ran the command sudo systemctl enable wifi-resume.service

Many thanks to Sean for solution.

Solution 2:

Solution what works fine for me:

sudo touch /etc/pm/sleep.d/10_restart_network_manager
sudo chmod +x /etc/pm/sleep.d/10_restart_network_manager
sudo gedit /etc/pm/sleep.d/10_restart_network_manager

Paste this code inside the file:

#!/bin/sh

case $1 in
    resume|thaw)
        sudo /bin/systemctl restart network-manager.service
    ;;
esac

Solution 3:

After many attempts at this annoying problem I came up with this solution. Create an executable file under /etc/pm/sleep.d/, and name it i.e. 10_resume_wifi, like this:

sudo touch /etc/pm/sleep.d/10_resume_wifi
sudo chmod +x /etc/pm/sleep.d/10_resume_wifi
sudo gedit /etc/pm/sleep.d/10_resume_wifi

Paste this code inside the file:

#!/bin/sh

case $1 in
     suspend|suspend_hybrid|hibernate)
        sudo nmcli n off
        ;;
     resume|thaw)
        sudo nmcli n on
        ;;
esac

Save and close the file, that's it.

This was the only solution that worked all the time. Note: Other solutions that I found used an older version of nmcli.