How to automatically unmount gvfs network shares before suspend?

Asked by Petr Helebrant

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:

#!/bin/sh

case "$1" in
        hibernate|suspend)
                /usr/bin/gvfs-mount --unmount-scheme=*
                ;;
        *) exit
                ;;
esac

Thanks for your advice!!

Question information

Language:
English Edit question
Status:
Expired
For:
Ubuntu GNOME Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

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

Revision history for this message
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.

#!/bin/bash

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
        hibernate|suspend)
                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
                ;;
esac