Results 1 to 10 of 25

Thread: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no errors!

Threaded View

  1. #1
    Join Date
    Oct 2009

    Arrow [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no errors!

    Updated: 12/12/09
    I've found that the following works on Ubuntu 9.10 Karmic while using wireless and WPA2 on my laptop:

    After hours of beating my head against the wall trying to figure out how to get rid of those time-consuming CIFS VFS errors during shutdown, I cobbled together this (ugly) fix.

    I take no credit for this script. I found it here. I simply put two and two together, as I guessed this script may execute before Network Manager is killed. I just plugged in the portion.
    • Save the script somewhere safe. I saved it in ~/Scripts, and gave it root-only permissions.
    • sudo chmod +x /path/to/script/scriptname
    • Add the script to your Start-up Applications. (System > Preferences > Startup Applications)

    #!/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 '' 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 ="sudo /etc/init.d/", 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 =
            #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:
    • Run in terminal:
      sudo visudo
    • Add the following to the bottom of the file:
      %admin ALL=NOPASSWD: /etc/init.d/

    • Press Ctrl-X to exit, press Y to save changes, and hit [Enter] to write the file.

    I hope this helps! I'm a linux noob, so apologies if my guide wasn't perfect.
    (Credit to stevo1982 for the sudo password workaround!)
    Last edited by ubradford; December 12th, 2009 at 12:13 PM. Reason: Added stevo1982's workaround.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts