From bc7c44b57d445b4bf1c4d2403e16e1d1a32c46c7 Mon Sep 17 00:00:00 2001 From: liuheng Date: Wed, 26 Jul 2023 10:47:28 +0800 Subject: [PATCH] =?UTF-8?q?gs=5Fpostuninstall=E5=88=A0=E9=99=A4cgroup?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/postuninstall/PostUninstallImpl.py | 25 ++++++++++++++++++- script/local/PreInstallUtility.py | 11 ++++++++ script/local/UnPreInstallUtility.py | 24 ++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/script/impl/postuninstall/PostUninstallImpl.py b/script/impl/postuninstall/PostUninstallImpl.py index 696cae90..326a4c51 100644 --- a/script/impl/postuninstall/PostUninstallImpl.py +++ b/script/impl/postuninstall/PostUninstallImpl.py @@ -60,7 +60,7 @@ ACTION_CLEAN_GAUSS_ENV = "clean_gauss_env" ACTION_DELETE_GROUP = "delete_group" ACTION_CLEAN_SYSLOG_CONFIG = 'clean_syslog_config' ACTION_CLEAN_DEPENDENCY = "clean_dependency" - +ACTION_DELETE_CGROUP = "delete_cgroup" class PostUninstallImpl: """ @@ -118,6 +118,8 @@ class PostUninstallImpl: try: # check uninstall self.checkUnPreInstall() + # clean cgroup + self.clean_cgroup() # clean app/log/data/temp dirs self.cleanDirectory() # clean other user @@ -170,6 +172,27 @@ class PostUninstallImpl: self.mpprcFile) self.logger.log("Successfully checked unpreinstallation.") + def clean_cgroup(self): + """ + function: clean cgroup + input : NA + output: NA + """ + self.logger.log("clean cgroup") + + cmd = "%s -t %s -u %s -l '%s' -X '%s'" % ( + OMCommand.getLocalScript("Local_UnPreInstall"), + ACTION_DELETE_CGROUP, + self.user, + self.localLog, + self.xmlFile) + self.logger.debug("Command for clean cgroup: %s" % cmd) + # check if do postuninstall in all nodes + CmdExecutor.execCommandWithMode(cmd, + self.sshTool, self.localMode, + self.mpprcFile) + self.logger.log("Successfully clean cgroup.") + def cleanDirectory(self): """ function: clean install/instance/temp dirs diff --git a/script/local/PreInstallUtility.py b/script/local/PreInstallUtility.py index e3f96395..0e011460 100644 --- a/script/local/PreInstallUtility.py +++ b/script/local/PreInstallUtility.py @@ -2586,6 +2586,17 @@ Common options: os.makedirs(dest_path) FileUtil.changeOwner("root", dest_path) + # cp cgroup to /root/gauss_om/xxx + self.logger.debug("cp cgroup to /root/gauss_om/xxx.") + root_lib_dir = os.path.join(dest_path, "lib") + root_bin_dir = os.path.join(dest_path, "bin") + FileUtil.createDirectory(root_lib_dir, mode=DefaultValue.KEY_DIRECTORY_MODE) + FileUtil.createDirectory(root_bin_dir, mode=DefaultValue.KEY_DIRECTORY_MODE) + libcgroup_dir = os.path.realpath("%s/libcgroup/lib/libcgroup.so*" % package_path) + cgroup_exe_dir = os.path.realpath("%s/libcgroup/bin/gs_cgroup" % package_path) + cp_cmd = "cp -rf %s %s; cp -rf %s %s" % (libcgroup_dir, root_lib_dir, cgroup_exe_dir, root_bin_dir) + CmdExecutor.execCommandLocally(cp_cmd) + # cp $GPHOME script lib to /root/gauss_om/xxx cmd = ("cp -rf %s/script %s/lib %s/version.cfg %s" % (self.clusterToolPath, self.clusterToolPath, diff --git a/script/local/UnPreInstallUtility.py b/script/local/UnPreInstallUtility.py index b1fafe7d..66be050d 100644 --- a/script/local/UnPreInstallUtility.py +++ b/script/local/UnPreInstallUtility.py @@ -46,6 +46,7 @@ ACTION_CLEAN_TOOL_ENV = 'clean_tool_env' ACTION_CHECK_UNPREINSTALL = "check_unpreinstall" ACTION_CLEAN_GAUSS_ENV = "clean_gauss_env" ACTION_DELETE_GROUP = "delete_group" +ACTION_DELETE_CGROUP = "delete_cgroup" # clean instance paths ACTION_CLEAN_INSTANCE_PATHS = "clean_instance_paths" # clean $GAUSS_ENV @@ -477,6 +478,27 @@ class Postuninstall(LocalBaseOM): self.logger.debug("Cleaned $GAUSS_ENV.") + def clean_cgroup(self): + """ + function: clean cgroup + input : NA + output: NA + """ + self.logger.debug("Cleaning user cgroup.") + # mkdir gauss_home dir + gsom_path = DefaultValue.ROOT_SCRIPTS_PATH + root_lib_dir = "%s/%s/lib/" % (gsom_path, self.user) + root_bin_dir = "%s/%s/bin/" % (gsom_path, self.user) + + # delete cgroup + cmd = "export LD_LIBRARY_PATH=%s:\$LD_LIBRARY_PATH && %s/gs_cgroup -d -U %s" % (root_lib_dir, root_bin_dir, self.user) + (status, output) = subprocess.getstatusoutput(cmd) + if status != 0: + self.logger.logExit( + "Error: Failed to delete cgroup " + "cmd:%s. Error: \n%s" % (cmd, output)) + self.logger.debug("Successfully cleaned user cgroup.") + def cleanGroup(self): """ function: clean group @@ -603,6 +625,8 @@ class Postuninstall(LocalBaseOM): self.cleanGaussEnv() elif self.action == ACTION_DELETE_GROUP: self.cleanGroup() + elif self.action == ACTION_DELETE_CGROUP: + self.clean_cgroup() elif self.action == ACTION_CLEAN_DEPENDENCY: self.cleanScript() elif self.action == ACTION_CLEAN_ENV: -- Gitee