I have a specific problem. I would like to auto-unmount a samba (cifs) share before suspend or shutdown my computer. So I created a script in /lib/systemd/system-sleep
to be able to do this.
#!/bin/sh
case $1/$2 in
pre/*)
if mountpoint -q /path/to/share # if share is mounted
then
umount /path/to/share # unmount
else
exit 0 # otherwise do nothing
fi
;;
esac
The problem with this script is that if the computer goes to sleep (suspend), all network connections are killed / terminated (wireless / wired too) before this script can be executed. So without internet connection the script can't examine whether /path/to/share
mounted or not and it freezes the whole system for ~1 minute.
If I add service network-manager restart
before if statement, it works perfectly, because it re-estabilishes internet connections after they were killed. It can be a solution, but not too good: it increases the neccessary time to be suspended. It would be better if I could prevent killing / terminating connections before suspend or delay (at least until the script is executed).