For systemd
on Ubuntu 16.04 you should also consider the "pre" (suspend) and "post" (resume) argument in ${1}
so that the restart executes only after leaving system suspend.
I also had to add a sleep
to give the network scan enough time to complete (my best guess).
$ sudo cat /lib/systemd/system-sleep/network-manager-restart
#!/bin/sh
set -e
if [ "$2" = "suspend" ] || [ "$2" = "hybrid-sleep" ]; then
case "$1" in
post) sleep 10 ; systemctl restart network-manager ;;
esac
fi
For more details read: https://www.freedesktop.org/software/systemd/man/systemd-suspend.service.html
Immediately before entering system suspend and/or hibernation
systemd-suspend.service (and the other mentioned units, respectively)
will run all executables in /usr/lib/systemd/system-sleep/ and pass
two arguments to them. The first argument will be "pre", the second
either "suspend", "hibernate", or "hybrid-sleep" depending on the
chosen action. Immediately after leaving system suspend and/or
hibernation the same executables are run, but the first argument is
now "post". All executables in this directory are executed in
parallel, and execution of the action is not continued until all
executables have finished.