Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a couple of folders containing compressed data. I have one application which needs to access the uncompressed version of the same data.

A simple way to solve that for me has been to run a script upon login looking something like this:

#!/bin/bash
rar2fs -o allow_other /home/user/source1        /home/user/target1
rar2fs -o allow_other /home/user/source2        /home/user/target2
rar2fs -o allow_other /home/user/source3        /home/user/target3
rar2fs -o allow_other /home/user/source4        /home/user/target4

To get the script to run when I login was simple, I just added it using 'Startup Applications'.

I just now realized however that my approach comes up short when I log out then back in again.

My guess is it works badly since the rar2fs/fuse mounts happen within my encrypted home folder. When I log out I think ubuntu locks the encryption, but my mount probably stick around even though both source and target are inaccessible.

Then when I login again, adding insult to injury, I try to do the mount again. Leaving me with mountpoints that spit out errors like when I try to access them:

Error: Error when getting information for file '/home/user/target1':Transport endpoint is not connected

My guess is this could be prevented if I could just get the system to unmount properly on logout, but I don't know how to get a script to run upon logout.

How does one properly shut down a fuse mount before logout?

EDIT: I'm using unity.

EDIT:

Running fusermount -u using session-cleanup-script I get the following error:

fusermount: bad mount point /home/user/target1: No such file or directory

I've also tried adding the umount loop to my mount script so that it should umount the folders before mounting them if they are already mounted, but those umounts fail as well:

fusermount: failed to unmount /home/user/target1: Invalid argument

My guess is that the first solution fails because the encrypted home locks before the cleanup-script is run. Perhaps there is some way to hook into the encryption routine and have a script run before the home folder locks?

If I run the umount-script manually before logging out the mountpoints work as expected when I login again.

share|improve this question

1 Answer 1

I have a problem similar to yours, except I use SSHFS. I think my solution can be easily adapted for your scenario.

In /etc/lightdm/lightdm.conf, under the section [SeatDefaults], the following option points to a file that runs when quitting a user session (runs as root):

session-cleanup-script=/path/to/file

A fuse mount can be unmounted running fusermount -u /path/to/mount/point, but only the user who mounted it can unmount it. So I had to use su to change the user before fusermount -u. This is my logout script:

#!/bin/bash

# Change user
if [ "$EUID" = "0" -a "$USER" != "root" ]; then
    su -c $0 $USER &
    exit 0
fi

# Unmount sshfs sharings at the end of the session
for MNTPOINT in `mount -t fuse.sshfs | grep -i "user=$USER" | cut -d" " -f 3`; do
        fusermount -u $MNTPOINT
done

exit 0

All you have to do is replace fuse.sshfs with the correct filesystem type, which you can find out in mount output.

share|improve this answer
    
While your suggestion showed much promise I'm afraid the home folder encryption is locked before the cleanup-script is run. My fusermounts get an error: "fusermount: bad mount point /home/user/target1: No such file or directory" –  azzid Mar 6 '13 at 10:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.