Score:1

How to prevent (or delay) wifi / ethernet sleep before suspend?

cn flag

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

Score:0
lt flag
sup

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.