Part 1) WiFi module suspend scripts:
Create a simple script to unload your network WiFi module before entering suspend. Substitute in your Wifi module where appropriate.
#!/bin/bash
modprobe -r 8812au
Save as /usr/bin/netmod-suspend.sh & make it executable and owned by root:
sudo chown root:root /usr/bin/netmod-suspend.sh
sudo chmod +x /usr/bin/netmod-suspend.sh
Create a systemd unit file with the following contents:
# cat netmod-suspend.service
# /etc/systemd/system/netmod-suspend.service
[Unit]
Description=Network module suspend helper
Before=sleep.target
[Service]
Type=simple
ExecStart=-/usr/bin/netmod-suspend.sh
[Install]
WantedBy=sleep.target
Save it as /etc/systemd/system/netmod-suspend.service & make it executable and owned by root
sudo chown root:root /etc/systemd/system/netmod-suspend.service
sudo chmod +x /etc/systemd/system/netmod-suspend.service
Then:
sudo systemctl enable netmod-suspend.service
sudo systemctl start netmod-suspend.service
This sucessfully unloaded the wifi module before suspend. I did not write the other systemd unit file to automatically load the wifi module after resume. No point as your solution was working fine. I simply ran:
sudo modprobe 8812au
(Edit) - Part 2 (below) contains the scripts to load your WiFi modules after resuming from suspend.
Part 2) WiFi module resume scripts:
Create a simple script to load your network WiFi module after resuming from suspend. Substitute in your Wifi module where appropriate.
#!/bin/bash
modprobe 8812au
Save as /usr/bin/netmod-resume.sh & make it executable and owned by root.
sudo chown root:root /usr/bin/netmod-resume.sh
sudo chmod +x /usr/bin/netmod-resume.sh
Create a systemd unit file with the following contents:
# systemctl cat netmod-resume.service
# /etc/systemd/system/netmod-resume.service
[Unit]
Description=Network module resume helper
After=suspend.target
[Service]
Type=simple
ExecStart=-/usr/bin/netmod-resume.sh
[Install]
WantedBy=suspend.target
Save it as /etc/systemd/system/netmod-resume.service & make it executable and owned by root.
sudo chown root:root /etc/systemd/system/netmod-resume.service
sudo chmod +x /etc/systemd/system/netmod-resume.service
Then:
sudo systemctl enable netmod-resume.service
sudo systemctl start netmod-resume.service
Part 1 + Part 2 are complete working suspend and resume WiFi service scripts. The scripts may be modified to suspend /resume bluetooth modules as well (or instead of wifi).