[omd-commits] OMD Git: omd: omd cp/mv: abort if there are still processes running of the previous user

git version control git at mathias-kettner.de
Thu Nov 20 09:43:21 CET 2014


Module:   omd
Branch:   master
Commit:   2a9c21a6e0ba92f6c087ed51994cff936d953ad4
URL:      http://omdistro.org/projects/omd/repository/revisions/2a9c21a6e0ba92f6c087ed51994cff936d953ad4

Author:   Mathias Kettner <mk at mathias-kettner.de>
Date:     Thu Nov 20 09:43:18 2014 +0100
Commiter: Mathias Kettner <mk at mathias-kettner.de>
Date:     Thu Nov 20 09:43:18 2014 +0100

omd cp/mv: abort if there are still processes running of the previous user

---

 packages/omd/.f12 |    2 +-
 packages/omd/omd  |   12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/packages/omd/.f12 b/packages/omd/.f12
index ce58226..2d00697 100644
--- a/packages/omd/.f12
+++ b/packages/omd/.f12
@@ -10,7 +10,7 @@ for hook in *.hook; do
     sudo cp -v $hook /omd/versions/default/lib/omd/hooks/${hook%*.hook}
     sudo chmod +x /omd/versions/default/lib/omd/hooks/${hook%*.hook}
 done
-sudo mkdir /omd/versions/default/lib/omd/scripts/post-create
+sudo mkdir -p /omd/versions/default/lib/omd/scripts/post-create
 
 OLD_VERSION=$(sed -rn < /omd/versions/default/bin/omd 's/^OMD_VERSION = "(.*)"$/\1/p')
 echo $OLD_VERSION
diff --git a/packages/omd/omd b/packages/omd/omd
index 3fa1512..b7b9825 100644
--- a/packages/omd/omd
+++ b/packages/omd/omd
@@ -437,6 +437,13 @@ def site_is_empty(sitename):
             return False
     return True
 
+def find_processes_of_user(username):
+    try:
+        return os.popen("pgrep -u '%s'" % username).read().split()
+    except:
+        return []
+
+
 def groupdel(groupname):
     os.system("groupdel " + groupname)
 
@@ -2471,6 +2478,11 @@ def main_mv_or_cp(what, args, options={}):
     if not site_is_stopped(old):
         bail_out("Cannot %s site '%s' while it is running." % (action, old))
 
+    pids = find_processes_of_user(old)
+    if pids:
+        bail_out("Cannot %s site '%s' while there are processes owned by %s.\n"
+                 "PIDs: %s" % (action, old, old, " ".join(pids)))
+
     if what == "mv":
         unmount_tmpfs(old, kill = "kill" in options)
         if not reuse:



More information about the omd-commits mailing list