1

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).

1 Answer 1

0

Put the script to

/etc/NetworkManager/dispatcher.d/pre-down.d/

Network Manager listens for the system call that suspends the computer on its down, independently from systemd, so this must be done through Network Manager.

Note that this will trigger the script whenever an interface goes down, wich is fine on my machine but might not be on yours. One could probably check whether a D-Bus signal to suspend has been emitted, but I have not explored that. There is a ticket about this on Network Manager gitlab tracker: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/910.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .