Hardcore Linux

Anything about Ubuntu, Centos, openSuSe and Fedora

Automatically unmount CIFS before Network-Manager Ubuntu 10.04

Even though my previous article already fixed my problem (esp. on Ubuntu 10.04), browsing the net last night and found this script which is way much easier and more effective than my previous:

How to use the script:

1. Save it in your personal script folder (mine usually $HOME/bin), for now I named it umountcifs.sh

2. Make the script executable

$> chmod +x $HOME/bin/umountcifs.sh

3. Add it in your Gnome’s startup application. (System > Preferences > Startup Applications)

4. Modify the file /etc/sudoers  or you can issue

$> sudo visudo

5. Add the following line or append it line with

ALL ALL=(ALL) NOPASSWD: /etc/init.d/umountnfs.sh

6. Done.

Here’s the scripts:

#!/usr/bin/env python

#Author: Seamus Phelan

#This program runs a custom command/script just before gnome shuts
#down.  This is done the same way that gedit does it (listening for
#the 'save-yourself' event).  This is different to placing scipts
#in /etc/rc#.d/ as the script will be run before gnome exits.
#If the custom script/command fails with a non-zero return code, a
#popup dialog box will appear offering the chance to cancel logout
#Usage: 1 - change the command in the 'subprocess.call' in
#           function 'session_save_yourself' below to be what ever
#           you want to run at logout.
#       2 - Run this program at every gnome login (add via menu System
#           -> Preferences -> Session)

import sys
import subprocess
import datetime

import gnome
import gnome.ui
import gtk

class Namespace: pass
ns = Namespace()
ns.dialog = None

def main():
    prog = gnome.init ("gnome_save_yourself", "1.0", gnome.libgnome_module_info_get(), sys.argv, [])
    client = gnome.ui.master_client()
    #set up call back for when 'logout'/'Shutdown' button pressed
    client.connect("save-yourself", session_save_yourself)
    client.connect("shutdown-cancelled", shutdown_cancelled)

def session_save_yourself( *args):
    #Unmount those CIFS shares!
    retcode = subprocess.call("sudo /etc/init.d/umountnfs.sh", shell=True)
    if retcode != 0:
        #command failed
    return True

def shutdown_cancelled( *args):
    if ns.dialog != None:
    return True

def show_error_dialog():
    ns.dialog = gtk.Dialog("There was a problem running your pre-shutdown script",
                           gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                           ("There was a problem running your pre-shutdown script - continue logout", gtk.RESPONSE_ACCEPT))
    if ns.test_mode == True:
        response = ns.dialog.run()
        #when in shutdown mode gnome will only allow you to open a window using master_client().save_any_dialog()
        #It also adds the 'Cancel logout' button

#Find out if we are in test mode???
if len(sys.argv) >=2 and sys.argv[1] == "test":
    ns.test_mode = True
    ns.test_mode = False

if ns.test_mode == True:

3 responses to “Automatically unmount CIFS before Network-Manager Ubuntu 10.04

  1. iamapizza July 13, 2010 at 11:24 pm

    I tried out a lot of steps from this thread:

    But none of them worked on Ubuntu 10.04. Trying yours worked.

    The shutdown splash screen still shows a TERM related error message but the shutdown is very fast now, so it shouldn’t bother many people.

    Thanks for your post!

  2. Pablo July 27, 2010 at 1:07 am

    works wonderfull on my notebook

    thanks a lot!

  3. Pingback: Ubuntu 11.04 Shutdown and Restart Problem with CIFS « Hardcore Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: