[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 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:
- 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!)
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Thanks, ubradford. This worked for me! :D
It should be possible to fix the security issue by having the script refer to a credentials file instead of putting your password in plain text in the script?
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Quote:
Originally Posted by
Ian Ferguson
Thanks, ubradford. This worked for me! :D
It should be possible to fix the security issue by having the script refer to a credentials file instead of putting your password in plain text in the script?
I'll play around with it and try to figure out how to echo the contents of a file into sudo. I never thought of that, I'm just a noob. lol :D
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Just one curious thing. I tested this by clicking "Restart" in the shutdown menu, and my ststem shut down and restarted cleanly, but when I click "Shut Down" it gets as far as a blank screen with a flashing cursor, but doesn't power off as it used to.
Also, it doesnt work when I change ownership of the script to root. I have to keep ownership of it myself.
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Quote:
Originally Posted by
Ian Ferguson
Just one curious thing. I tested this by clicking "Restart" in the shutdown menu, and my ststem shut down and restarted cleanly, but when I click "Shut Down" it gets as far as a blank screen with a flashing cursor, but doesn't power off as it used to.
Also, it doesnt work when I change ownership of the script to root. I have to keep ownership of it myself.
The ownership and permissions of my script from "ls -la" are as follows:
Code:
-rwxr-xr-x 1 root root 2496 2009-12-06 04:00 gnomelogout
I've tried "Restart" and "Shut Down" from both gnome-panel and from the "Shut Down the Computer" dialogue box when pressing the power button on my machine. It is working cleanly in all situations. I do however notice that the shut-down splash screen will break from time to time and let a login prompt flash up on the screen for just a second before the machine powers off entirely.
Maybe another script / program running during logout is conflicting somehow? Or have you played around with the order of script execution in /etc/rc0.d/ and /etc/rc6.d/ ? Maybe one of those could be causing a problem for you at shut-down? Both are just guesses, I'm by far not an expert.
Also, it looks like shutting down from terminal with either:
or will break the script. I'd have to guess that gnome never gets a chance to send out the "save-yourself" event the script is listening for when the computer is shut down in that manner.
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
All working now. Turns out that in trying out different fixes, I'd messed up rc0.d, so that's why it wasn't shutting down properly.
Just as well I'd already learned the lesson about making backups before editing system and config files!;)
I've also found this script doesn't work when I shut down or restart from command line. I guess that must bypass the Gnome shutdown sequence.
It occurs to me that this script would be useful if there are other tasks (e.g. backup or synchronize files) that you want to perform automatically on shutdown, but which need the network connection to still be up.
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Hi folks.
Quote:
Thanks, ubradford. This worked for me!
It should be possible to fix the security issue by having the script refer to a credentials file instead of putting your password in plain text in the script?
I changed the line:
Code:
retcode = subprocess.call("echo SUDOPASSWORD | sudo -S /etc/init.d/umountnfs.sh", shell=True)
to
Code:
retcode = subprocess.call("sudo /etc/init.d/umountnfs.sh", shell=True)
and added this to the bottom of my /etc/sudoers file:
Code:
%admin ALL=NOPASSWD: /etc/init.d/umountnfs.sh
that way I don't need to put the password in the script.
Works just as good for me.
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
Quote:
that way I don't need to put the password in the script.
Works just as good for me.
Thanks stevo1982! I'll update the original post with your information. :D
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
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!
Re: [Fix] Karmic: Automaticly unmount CIFS shares at shutdown & restart with no error
I'm also looking for a fix which works in KDE4.
What i already tried:
- Putting the umountscript in ~/.kde/shutdown/
/etc/network/if-down.d
/etc/Networkmanager/dispatcher.d
- Adding the command in /etc/kde4/kdm/XReset
In all cases the shutdown hangs for several minutes just at different places of the shutdown process.
I thought the script in ~/.kde/Shutdown should do the trick, but it seems even those scripts are executed AFTER the networkmanager kills the connection.
I'm using wireless and WPA2 on kubuntu karmic amd64.