[omd-commits] OMD Git: omd: New option --kill for rm, disable and umount

git version control git at mathias-kettner.de
Mon Jan 16 13:44:50 CET 2012


Module:   omd
Branch:   master
Commit:   85c84166b88830ebff0c9fbe6d33fb372734eedc
URL:      http://omdistro.org/projects/omd/repository/revisions/85c84166b88830ebff0c9fbe6d33fb372734eedc

Author:   Mathias Kettner <mk at mathias-kettner.de>
Date:     Mon Jan 16 13:44:05 2012 +0100
Commiter: Mathias Kettner <mk at mathias-kettner.de>
Date:     Mon Jan 16 13:44:05 2012 +0100

New option --kill for rm, disable and umount

This will automatically kill all processes using
tmpfs by use of fuser - in case the first unmount
is not successful.

---

 Changelog          |    2 ++
 packages/omd/omd   |   36 ++++++++++++++++++++++--------------
 packages/omd/omd.8 |   22 ++++++++++++++++++----
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/Changelog b/Changelog
index 1c3cdb9..59eba82 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,8 @@ This file documents the revision history for the Open Monitoring Distribution
 0.54
           - omd:
             - FIX: Fixed "omd umount" command when running without specific site
+            - new option --kill for umount, rm and disable, that will kill
+              processes using tmpfs before unmounting it
           - mod_python:
             - Fix "omd stop apache", which was sometimes timing out
             - Fix several DeprecationWarning messages when using python 2.6
diff --git a/packages/omd/omd b/packages/omd/omd
index 4898dfd..fd22c21 100644
--- a/packages/omd/omd
+++ b/packages/omd/omd
@@ -680,10 +680,12 @@ def create_tmpfs(sitename):
     chown_tree(tmp, sitename)
     ok()
 
-def unmount_tmpfs(sitename, output = True):
+def unmount_tmpfs(sitename, output = True, kill = False):
     # Clear directory hierarchy when not using a tmpfs
     # During omd update TMPFS hook might not be set so assume
     # that the hook is enabled by default.
+    # If kill is True, then we do an fuser -k on the tmp
+    # directory first.
     config_load_hooks()
     if g_hooks.get("TMPFS", {'value': 'on'})["value"] != "on":
         tmp = tmp_dir(sitename)
@@ -706,8 +708,13 @@ def unmount_tmpfs(sitename, output = True):
                     ok()
                 return True
 
+            if kill:
+                if output:
+                    sys.stdout.write("Killing processes still using '%s'\n" % tmp_dir(sitename))
+                os.system("fuser --silent -k '%s'" % tmp_dir(sitename))
+
             if output:
-                sys.stdout.write(".")
+                sys.stdout.write(kill and "K" or ".")
                 sys.stdout.flush()
             time.sleep(1)
 
@@ -2212,13 +2219,12 @@ def main_rm(args, options={}):
     #execute_as_user(stop_site, (g_sitename, ))
     os.system('omd stop %s' % g_sitename)
 
-    reuse = False
-    if "reuse" in options:
-        reuse = True
+    reuse = "reuse" in options
+    kill = "kill" in options
 
-    if user_logged_in(g_sitename):
+    if not kill and user_logged_in(g_sitename):
         bail_out("User '%s' still logged in or running processes." % g_sitename)
-    unmount_tmpfs(g_sitename)
+    unmount_tmpfs(g_sitename, kill=kill)
 
     if not reuse:
         remove_from_fstab(g_sitename)
@@ -2255,7 +2261,7 @@ def main_disable(args, options):
         sys.exit(0)
 
     stop_if_not_stopped(g_sitename) 
-    unmount_tmpfs(g_sitename)
+    unmount_tmpfs(g_sitename, kill = "kill" in options)
     sys.stdout.write("Disabling Apache configuration for this site...")
     delete_apache_hook(g_sitename)
     ok()
@@ -2294,7 +2300,7 @@ def main_mv_or_cp(what, args, options={}):
         bail_out("Cannot %s site '%s' while it is running." % (action, old))
 
     if what == "mv":
-        unmount_tmpfs(old)
+        unmount_tmpfs(old, kill = "kill" in options)
         if not reuse:
             remove_from_fstab(old)
 
@@ -2642,7 +2648,7 @@ def main_umount(args, options = {}):
             sys.stdout.write("%sUnmounting tmpfs of site %s%s..." % (tty_bold, site, tty_normal))
 	    sys.stdout.flush()
 
-            if not unmount_tmpfs(site, False):
+            if not unmount_tmpfs(site, False, kill="kill" in options):
                 sys.stdout.write(tty_error + "\n")
                 exit_status = 1
             else:
@@ -2651,7 +2657,7 @@ def main_umount(args, options = {}):
         # Skip the site even when it is partly running
         if not site_is_stopped(g_sitename):
             bail_out("Cannot unmount tmpfs of site '%s' while it is running." % g_sitename)
-        unmount_tmpfs(g_sitename)
+        unmount_tmpfs(g_sitename, kill="kill" in options)
     sys.exit(0)
 
 
@@ -2781,7 +2787,8 @@ commands = [
     "Populate site directory with default files and enable the site", ""),
 
   ( "rm",        True,  1, 1, True, "",        main_rm,
-    [ ( "reuse", None, False ) ],
+    [ ( "reuse", None, False ),
+      ( "kill", None, False )],
     "Remove a site (and its data)",
 
     "PLEASE NOTE: This action removes all configuration files\n"
@@ -2797,7 +2804,7 @@ commands = [
     "- Restart the system wide apache daemon\n"),
 
   ( "disable",   True,  1, 1, False, "", main_disable,
-    [],
+    [( "kill", None, False )],
     "Disable a site (stop it, unmount tmpfs, remove Apache hook)",
     "" ),
 
@@ -2875,7 +2882,8 @@ commands = [
     ""),
 
   ( "umount",      False, 2, 1, False, "", main_umount,
-    [ ( "version", "V", True ) ],
+    [ ( "version", "V", True ),
+      ( "kill", None, False ) ],
     "Umount ramdisk volumes of site(s)",
     ""),
 
diff --git a/packages/omd/omd.8 b/packages/omd/omd.8
index e777996..c0d296f 100644
--- a/packages/omd/omd.8
+++ b/packages/omd/omd.8
@@ -128,12 +128,17 @@ configuration files and enabling the site (see \fBomd disable\fP). Afterwards
 the site is in the same state as after an \fBomd create\fP without \fB--no-init\fP.
 
 .TP
-.B omd [-f, --force] rm         SITE             
+.B omd [-f, --force] [--kill] rm         SITE             
 Remove a site and all of its data. This includes deleting the
 directory \fB/omd/sites/\fPSITE and removing the system user
 and group of that site. This - of course - needs root permissions.
+
+The option \fB--kill\fP will automatically kill all processes that
+use the temporary filesystem of the site before unmounting it.
+Otherwise the unmount and the removal of the site will fail.
+
 .TP
-.B omd disable SITE
+.B omd disable [--kill] SITE
 Disable a site. First the site will be stopped, if it is running.
 Then the tmpfs will be unmounted and the site will be made unknown
 to the global Apache server (by emptying the file /omd/apache/SITE.conf
@@ -147,6 +152,11 @@ or program. It can safely be unmounted. This is convenient in
 situations where the site is clustered and the site's home directory
 shall be moved to another cluster node.
 
+Since unmounting the tmpfs will only be possible if no process
+is using it, you can specify \fB--kill\fP to automatically kill
+all such processes before the unmount. This is especially useful if
+omd disable is used in cluster-failover scripts.
+
 Disabling a site needs root permissions.
 
 .TP
@@ -275,10 +285,14 @@ to make the output more human readable, so it is better parseable by scripts.
 This command also handles the global option \fB-v\fP or \fB--verbose\fP. It shows the
 changes in detail.
 .TP
-.B omd umount [SITE]
+.B omd umount [--kill] [SITE]
 Unmounts the ramdisk filesystem (tmpfs) of the given or all sites if no SITE option given.
 
-The ramdisk can only be unmounted when a site is stopped.
+The ramdisk can only be unmounted when a site is stopped and no processes are currently
+using it (have a directory in it as current directory are have an open file in it).
+If you specify \fB--kill\FP, then omd will kill processes using the filesystem using
+\fBfuser -k\fP.
+
 .SH SEE ALSO
 .BR http://www.omdistro.org
 .br



More information about the omd-commits mailing list