How to automatically unmount gvfs network shares before suspend?

Asked by Petr Helebrant on 2014-01-05

Hi all,
I am mounting remote filesystems with help of nautilus really often and it causes me troubles when I suspend my laptop and move to another location without internet connection. System hangs for a long time after entering login informations, I thinks it's related to some timeout of network mount and it's really anoying to hard shut down (long power button press) my laptop every time I move somewhere.

Is there any way to automatically unmount all gvfs shares before suspend? I tried to add some script to /usr/lib/pm-utils/sleep.d/ but it doesn't work, looks like this:


case "$1" in
                /usr/bin/gvfs-mount --unmount-scheme=*
        *) exit

Thanks for your advice!!

Question information

English Edit question
Ubuntu GNOME Edit question
No assignee Edit question
Last query:
Last reply:
Launchpad Janitor (janitor) said : #1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

yoyoma2 (sinbad-4273) said : #2

I created this file in /etc/pm/sleep.d (didn't work in /usr/lib/pm-utils/sleep.d). The difference is that these scripts run as root and 'gvfs-mount' needs to run as the same user running the gui and needs DBUS_SESSION_BUS_ADDRESS set correctly. This script sets DBUS_SESSION_BUS_ADDRESS and finds the username of the gui owner then uses 'sudo' to run 'gvfs-mount' as that user.


export DBUS_SESSION_BUS_ADDRESS=$(grep -z "DBUS_SESSION_BUS_ADDRESS" /proc/$(pidof gnome-session)/environ | cut -d= -f2-)
DBUS_USERNAME=$(grep -z "USER" /proc/$(pidof gnome-session)/environ | cut -d= -f2-)

case "$1" in
                sudo -E -u $DBUS_USERNAME /bin/bash -c "/usr/bin/gvfs-mount --list | /bin/grep -e '//' | /usr/bin/cut -d ' ' -f6 | /usr/bin/xargs -I {} /usr/bin/gvfs-mount --unmount {}"
        *) exit