Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

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

  1. #11
    Join Date
    May 2008
    Beans
    1

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    It only works for users who have "Administer the system" checked in the "User Privileges" tab in User Settings properties. The other ones cannot use the sudo command.

    So, if you have multiple users on a computer and only one has the admin rights, the problem is still opened.

    Any idea?

  2. #12
    Join Date
    Dec 2006
    Beans
    25

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    I'm using Jaunty with LXDE, getting the errors at shutdown caused by shares not unmounting. Would your script have any chance of working in a non-gnome environment? I have no clue if it makes a difference, but using GDM for login.

  3. #13
    Join Date
    Jan 2010
    Beans
    1

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Quote Originally Posted by ubradford View Post
    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 umountnfs.sh 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)

    Code:
    #!/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  
            show_error_dialog()
        return True
    
    def shutdown_cancelled( *args):
        if ns.dialog != None:
            ns.dialog.destroy()
        return True
    
    
    def show_error_dialog():
        ns.dialog = gtk.Dialog("There was a problem running your pre-shutdown script",
                               None,
                               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()
            ns.dialog.destroy()
        else:
            #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
            gnome.ui.master_client().save_any_dialog(ns.dialog)
    
    
    
    #Find out if we are in test mode???
    if len(sys.argv) >=2 and sys.argv[1] == "test":
        ns.test_mode = True
    else:
        ns.test_mode = False
    
    if ns.test_mode == True:
        main()
        session_save_yourself()
    else:
        main()
        gtk.main()
    • Run in terminal:
      Code:
      sudo visudo
    • Add the following to the bottom of the file:
      Code:
      %admin ALL=NOPASSWD: /etc/init.d/umountnfs.sh


    • 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!)
    Unfortunately this is solution still doesn't work for me :S, I'm using Ubuntu 9.10.

    You just added this script in the autostart application? You didn't add anything to /etc/rc0.d or rc6.d directory ??


    EDIT:
    It works if I shutdown from the gnome menu, it fail if I shutdown from th termina.
    Is there a solution for that issue?
    Last edited by impolo; January 11th, 2010 at 12:49 PM.

  4. #14
    Join Date
    Dec 2009
    Location
    Sydney, AU
    Beans
    13
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Thanks, this worked nicely for me
    Alienware M17X | QX9300 @ 3 GHz | GTX260M x2 SLI | 1920x1200 | 8GB 1333 Mhz | BD-ROM | Ubuntu 9.10 | 1TB 7K2 Raid 0

  5. #15
    Join Date
    Oct 2009
    Beans
    16

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Quote Originally Posted by impolo View Post
    Unfortunately this is solution still doesn't work for me :S, I'm using Ubuntu 9.10.

    You just added this script in the autostart application? You didn't add anything to /etc/rc0.d or rc6.d directory ??


    EDIT:
    It works if I shutdown from the gnome menu, it fail if I shutdown from th termina.
    Is there a solution for that issue?
    No solution I am aware of. See post #5 in this thread for an explanation.
    Last edited by ubradford; January 16th, 2010 at 07:44 AM.

  6. #16
    Join Date
    Oct 2009
    Beans
    16

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Quote Originally Posted by robbuntista View Post
    It only works for users who have "Administer the system" checked in the "User Privileges" tab in User Settings properties. The other ones cannot use the sudo command.

    So, if you have multiple users on a computer and only one has the admin rights, the problem is still opened.

    Any idea?
    There is likely a way to do this by embedding the admin's username and sudo password into the script. (Which is the way I originally had it set up.) Of course this comprimises security, so I wouldn't recommend it if you are worried about your normal users finding the script. Something like this may work:

    Replace line:
    Code:
    retcode = subprocess.call("sudo /etc/init.d/umountnfs.sh", shell=True)
    With:
    Code:
    retcode = subprocess.call("echo admin's_sudo_password | sudo -u admin's_username -S /etc/init.d/umountnfs.sh", shell=True)
    Replace admin's_sudo_password and admin's_username with your sudo password and username.

  7. #17
    Join Date
    Oct 2009
    Beans
    16

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Quote Originally Posted by chipbennett View Post
    Anyone know how to modify this script for KDE?

    I'm assuming all of those GNOME/GTK references aren't applicable for KDE/Kubuntu?

    Thanks in advance!
    The script will not work for KDE users, since the script is listening for a specific Gnome event. If someone can find a similar KDE event at shutdown, creating a script to listen for the event and execute commands may work. The trick is to run umountnfs.sh before network managers are killed.

  8. #18
    Join Date
    Oct 2009
    Location
    Mumbai, India
    Beans
    22
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    Hey All,

    I have had this problem too. I am working presently on Karmic and access network from wireless and wired connections at different times.

    I tried three different solutions for this problem:
    1. The one given here: http://ubuntuforums.org/showthread.php?t=1347340
    2. The one given by dmizer here: http://ubuntuforums.org/showthread.php?t=288534
    3. And the one given here: http://ubuntuforums.org/showthread.php?t=293513

    However none of the solutions fixed my problem. I read in one of the posts that the real problem was to run the /etc/init.d/umountnfs.sh before the system is killed.

    This gave me the simple idea, since I always have a terminal open, I wrote this bash function:

    function bringdown()
    {
    sudo /etc/init.d/umountnfs.sh && sudo shutdown -h now
    }

    This simply solves my problem.

    However I was thinking of a more generic solution. I have never tried scripting. I was wondering if there can be a more elegant and generic solution to this. I have an idea, someone please let me know if this is feasible.

    We can create a script which runs this function `bringdown' as given above (preferable without the need for a sudo password prompt [perhaps using a credentials file or editing visudo]) and put this in the $PATH of each user, so that one can simply call the run dialog and bring the system down.

    Please let me know if writing such a script is possible and easy. I am willing to learn and do homework if any is needed.

    Thanks for reading the long post. Hoping for some replies.

  9. #19
    Join Date
    Jul 2007
    Location
    Newcastle, Australia
    Beans
    20
    Distro
    Ubuntu

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    This fixes the problem for Xubuntu -

    Make links in the rc folders to umountnfs.sh that are earlier in the alphabet than the existing link to umountnfs.sh.

    # For shutdowns ..
    cd /etc/rc0.d
    sudo ln -s ../init.d/umountnfs.sh K02umountnfs

    # For reboots ..
    cd /etc/rc6.d
    sudo ln -s ../init.d/umountnfs.sh K02umountnfs
    (This doesn't work if you use '-n' with the smbmount command because umountnfs.sh reads the /etc/mtab file to find mounts.)
    Last edited by Tybion; January 22nd, 2010 at 10:54 AM. Reason: minor change

  10. #20
    Join Date
    Oct 2007
    Location
    Sydney, Australia
    Beans
    7
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error

    I was also having the same issue using Karmic but have fixed it.
    You can see my post here.

    Not certain, but it should work for kubuntu, xubuntu, etc as well.
    It also doesn't require any messing around with permissions.
    Last edited by solbot; February 2nd, 2010 at 07:43 PM. Reason: Specified Karmic as the system.

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

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