From 4bf2fe496500faab4eacd9e526424559e6901dea Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 28 Mar 2014 17:49:59 +0100 Subject: [PATCH] clean up the code that removes a slice from vsys's scope before its rootfs gets deleted however the bulk of that logic was in place already so I doubt this will fix the f20 issue --- plugins/vsys.py | 34 ++++++++++++++++++++++++++++++++-- sliver_lxc.py | 12 +++++------- tools.py | 8 ++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/plugins/vsys.py b/plugins/vsys.py index 8d4f34c..bac56a9 100644 --- a/plugins/vsys.py +++ b/plugins/vsys.py @@ -2,6 +2,7 @@ import logger import os +import tools VSYSCONF="/etc/vsys.conf" VSYSBKEND="/vsys" @@ -40,9 +41,16 @@ def GetSlivers(data, config=None, plc=None): _restart = writeConf(slices, parseConf()) or _restart # Write out the ACLs if writeAcls(scripts, parseAcls()) or _restart: - logger.log("vsys: restarting vsys service") - logger.log_call(["/etc/init.d/vsys", "restart", ]) + restartService() +# check for systemctl, use it if present +def restartService (): + if tools.has_systemctl(): + logger.log("vsys: restarting vsys service through systemctl") + logger.log_call(["systemctl", "restart", "vsys"]) + else: + logger.log("vsys: restarting vsys service through /etc/init.d/vsys") + logger.log_call(["/etc/init.d/vsys", "restart", ]) def createVsysDir(sliver): '''Create /vsys directory in slice. Update vsys conf file.''' @@ -146,3 +154,25 @@ def parseConf(): f.close() except: logger.log_exc("vsys: failed parseConf") return slicesinconf + + +# before shutting down slivers, it is safe to first remove them from vsys's scope +# so that we are sure that no dangling open file remains +# this will also restart vsys if needed +def removeSliverFromVsys (sliver): + current_slivers=parseConf() + new_slivers= [ s for s in current_slivers if s != sliver ] + if writeConf (current_slivers, new_slivers): + trashSliverVsys (sliver) + restartService() + else: + logger.log("vsys.removeSliverFromConf: no need to remove %s"%sliver) + + +def trashSliverVsys (sliver): + slice_vsys_area = "/vservers/%s/vsys"%sliver + if not os.path.exists(slice_vsys_area): + logger.log("vsys.trashSliverVsys: no action needed, %s not found"%slice_vsys_area) + return + ret=subprocess.call([ 'rm', '-rf' , slice_vsys_area]) + logger.log ("vsys.trashSliverVsys: Removed %s (retcod=%s)"%(slice_vsys_area,retcod)) diff --git a/sliver_lxc.py b/sliver_lxc.py index 92c6b6c..5121645 100644 --- a/sliver_lxc.py +++ b/sliver_lxc.py @@ -9,6 +9,7 @@ import os, os.path import grp from pwd import getpwnam from string import Template +from plugins.vsys import removeSliverFromVsys import libvirt @@ -295,13 +296,10 @@ unset pathmunge command = ['/usr/sbin/userdel', '-f', '-r', name] logger.log_call(command, timeout=15*60) - if os.path.exists(os.path.join(containerDir,"vsys")): - # Slivers with vsys running will fail the subvolume delete. - # A more permanent solution may be to ensure that the vsys module - # is called before the sliver is destroyed. - logger.log("destroying vsys directory and restarting vsys") - logger.log_call(["rm", "-fR", os.path.join(containerDir, "vsys")]) - logger.log_call(["/etc/init.d/vsys", "restart", ]) + # Slivers with vsys running will fail the subvolume delete. + # A more permanent solution may be to ensure that the vsys module + # is called before the sliver is destroyed. + removeSliverFromVsys (name) # Remove rootfs of destroyed domain command = ['btrfs', 'subvolume', 'delete', containerDir] diff --git a/tools.py b/tools.py index 862efc6..334f33f 100644 --- a/tools.py +++ b/tools.py @@ -310,6 +310,14 @@ def get_node_virt (): f.write(virt) return virt +### this return True or False to indicate that systemctl is present on that box +# cache result in memory as _has_systemctl +_has_systemctl=None +def has_systemctl (): + if _has_systemctl is None: + _has_systemctl = (subprocess.call([ 'systemctl', '--help' ]) == 0) + return _has_systemctl + # how to run a command in a slice # now this is a painful matter # the problem is with capsh that forces a bash command to be injected in its exec'ed command -- 2.43.0