!770 gs_checkos 工具使用报command not found(取消分离工具到root)
Merge pull request !770 from 赵晨/master
This commit is contained in:
commit
177b86b24e
@ -78,6 +78,7 @@ class Postuninstall(ParallelBaseOM):
|
||||
self.rootPasswd = ""
|
||||
self.ips = []
|
||||
self.root_ssh_agent_flag = False
|
||||
self.gauss_om_path = ""
|
||||
|
||||
def usage(self):
|
||||
"""
|
||||
@ -223,7 +224,7 @@ General options:
|
||||
self.mpprcFile = ""
|
||||
# if MpprcFile is not null
|
||||
if (self.mpprcFile != ""):
|
||||
# if no MpprcFile
|
||||
# if no MpprcFile, It has no environment separation, the environment variables are in the.bashrc.
|
||||
if (not os.path.exists(self.mpprcFile)):
|
||||
GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50201"]
|
||||
% "MPPRC file" + " %s."
|
||||
@ -276,7 +277,7 @@ General options:
|
||||
gaussEnv = output.strip()
|
||||
else:
|
||||
# check if has mpprcFile
|
||||
if (self.mpprcFile != ""):
|
||||
if (self.mpprcFile != "" and os.path.exists(self.mpprcFile)):
|
||||
userprofile = self.mpprcFile
|
||||
else:
|
||||
userprofile = ProfileFile.get_user_bashrc(self.user)
|
||||
@ -361,6 +362,7 @@ General options:
|
||||
dirName = os.path.dirname(self.logFile)
|
||||
self.localLog = os.path.join(dirName, ClusterConstants.LOCAL_LOG_FILE)
|
||||
self.userHome = DefaultValue.getUserHome(self.user)
|
||||
self.gauss_om_path = "/home/%s/gauss_om" % self.user
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
|
@ -59,4 +59,5 @@ class PostUninstallImplOLAP(PostUninstallImpl):
|
||||
self.rootPasswd = GaussPost.rootPasswd
|
||||
self.ips = GaussPost.ips
|
||||
self.root_ssh_agent_flag = GaussPost.root_ssh_agent_flag
|
||||
self.gauss_om_path = GaussPost.gauss_om_path
|
||||
|
||||
|
@ -124,10 +124,10 @@ class PostUninstallImpl:
|
||||
self.cleanDirectory()
|
||||
# clean other user
|
||||
self.cleanRemoteOsUser()
|
||||
# clean other nodes environment software and variable
|
||||
self.cleanOtherNodesEnvSoftware()
|
||||
# clean other nodes log
|
||||
self.cleanOtherNodesLog()
|
||||
# clean other nodes environment software and variable
|
||||
self.cleanOtherNodesEnvSoftware()
|
||||
# clean local node environment software and variable
|
||||
self.cleanLocalNodeEnvSoftware()
|
||||
# clean local user
|
||||
@ -178,8 +178,7 @@ class PostUninstallImpl:
|
||||
input : NA
|
||||
output: NA
|
||||
"""
|
||||
self.logger.log("clean cgroup")
|
||||
|
||||
self.logger.log("check and clean cgroup")
|
||||
cmd = "%s -t %s -u %s -l '%s' -X '%s'" % (
|
||||
OMCommand.getLocalScript("Local_UnPreInstall"),
|
||||
ACTION_DELETE_CGROUP,
|
||||
@ -426,6 +425,35 @@ class PostUninstallImpl:
|
||||
+ " Error: \n%s." % str(e))
|
||||
self.logger.log("Successfully deleted logs of other nodes.")
|
||||
|
||||
def cleanOthernodesBackupScript(self):
|
||||
"""
|
||||
function: clean othernodes gauss_om script
|
||||
"""
|
||||
# check if local mode
|
||||
if self.localMode:
|
||||
return
|
||||
self.logger.log("Deleting gauss_om of other nodes.")
|
||||
try:
|
||||
# get other nodes
|
||||
hostName = NetUtil.GetHostIpOrName()
|
||||
otherNodes = self.clusterInfo.getClusterNodeNames()
|
||||
for otherNode in otherNodes:
|
||||
if (otherNode == hostName):
|
||||
continue
|
||||
cmd = f"ssh root@%s 'rm -rf %s'" % (otherNode, self.gauss_om_path)
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
if status != 0:
|
||||
self.logger.logExit(
|
||||
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
|
||||
+ " Error:\n%s" % output)
|
||||
self.logger.debug(
|
||||
"Successfully deleted gauss_om of the nodes: %s." % otherNodes)
|
||||
except Exception as e:
|
||||
self.logger.logExit(
|
||||
ErrorCode.GAUSS_502["GAUSS_50207"] % "other nodes gauss_om"
|
||||
+ " Error: \n%s." % str(e))
|
||||
self.logger.log("Successfully deleted gauss_om of other nodes.")
|
||||
|
||||
def cleanLocalNodeEnvSoftware(self):
|
||||
"""
|
||||
function: clean local node environment software and variable
|
||||
@ -476,20 +504,24 @@ class PostUninstallImpl:
|
||||
datadir = node_info.datanodes[0].datadir
|
||||
datadir_escaped = datadir.replace("/", "\\/")
|
||||
basePort = node_info.datanodes[0].port
|
||||
userprofile = ProfileFile.get_user_bashrc(self.user)
|
||||
# clean local node environment variable
|
||||
cmd = "(if [ -s '%s' ]; then " % PROFILE_FILE
|
||||
cmd += "sed -i -e '/^export PATH=\$PATH:\/root\/gauss_om\/%s\/" \
|
||||
"script$/d' %s " % (self.user, PROFILE_FILE)
|
||||
cmd += "-e '/^export PATH=\$PATH:\$GPHOME\/script\/gspylib\/pssh\/bin:" \
|
||||
"\$GPHOME\/script$/d' %s " % PROFILE_FILE
|
||||
cmd = "(if [ -s '%s' ]; then " % userprofile
|
||||
cmd += "sed -i -e '/^export PATH=\/home\/%s\/gauss_om\/" \
|
||||
"script:\$PATH/d' %s " % (self.user, userprofile)
|
||||
cmd += "-e '/^export PATH=\$GPHOME\/script\/gspylib\/pssh\/bin:" \
|
||||
"\$GPHOME\/script:\$PATH/d' %s " % PROFILE_FILE
|
||||
cmd += "-e '/^export LD_LIBRARY_PATH=\$GPHOME\/script\/gspylib\/clib:" \
|
||||
"\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
|
||||
"\$LD_LIBRARY_PATH$/d' %s " % userprofile
|
||||
cmd += "-e '/^export LD_LIBRARY_PATH=\$GPHOME\/lib:" \
|
||||
"\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
|
||||
cmd += "-e '/^export PGDATABASE=postgres/d' %s " % PROFILE_FILE
|
||||
cmd += "-e '/^export PGPORT=%d/d' %s " %(basePort,PROFILE_FILE)
|
||||
cmd += "-e '/^export PGDATA=%s/d' %s " %(datadir_escaped,PROFILE_FILE)
|
||||
cmd +="-e '/^export PYTHONPATH=\$GPHOME\/lib$/d' %s; fi) " % PROFILE_FILE
|
||||
"\$LD_LIBRARY_PATH$/d' %s " % userprofile
|
||||
cmd += "-e '/^export PGDATABASE=postgres/d' %s " % userprofile
|
||||
cmd += "-e '/^export PGPORT=%d/d' %s " % (basePort, userprofile)
|
||||
cmd += "-e '/^export UNPACKPATH=/d' %s " % userprofile
|
||||
cmd += "-e '/^export COREPATH=/d' %s " % userprofile
|
||||
cmd += "-e '/^export GPHOME=/d' %s " % userprofile
|
||||
cmd += "-e '/^export PGDATA=%s/d' %s " % (datadir_escaped, userprofile)
|
||||
cmd += "-e '/^export PYTHONPATH=\$GPHOME\/lib$/d' %s; fi) " % userprofile
|
||||
|
||||
self.logger.debug(
|
||||
"Command for deleting environment variable: %s" % cmd)
|
||||
@ -500,7 +532,7 @@ class PostUninstallImpl:
|
||||
+ " Error: \n%s" % output)
|
||||
# check if user profile exist
|
||||
user_bashrc = ProfileFile.get_user_bashrc(self.user)
|
||||
if (self.mpprcFile is not None and self.mpprcFile != ""):
|
||||
if (self.mpprcFile is not None and self.mpprcFile != "" and os.path.exists(self.mpprcFile)):
|
||||
userProfile = self.mpprcFile
|
||||
else:
|
||||
userProfile = user_bashrc
|
||||
@ -896,11 +928,13 @@ class PostUninstallImpl:
|
||||
tmp_path = "%s/gaussdb_tmp" % homeDir
|
||||
|
||||
# get cmd
|
||||
bashrc_file = os.path.join(pwd.getpwuid(os.getuid()).pw_dir, ".bashrc")
|
||||
bashrc_file = ProfileFile.get_user_bashrc(self.user)
|
||||
kill_ssh_agent_cmd = "ps ux | grep 'ssh-agent' | grep -v grep | awk '{print $2}' | " \
|
||||
"xargs kill -9"
|
||||
delete_line_cmd = " && sed -i '/^\\s*export\\s*SSH_AUTH_SOCK=.*$/d' %s" % bashrc_file
|
||||
delete_line_cmd += " && sed -i '/^\\s*export\\s*SSH_AGENT_PID=.*$/d' %s" % bashrc_file
|
||||
delete_line_cmd = ""
|
||||
if os.path.exists(bashrc_file):
|
||||
delete_line_cmd += " && sed -i '/^\\s*export\\s*SSH_AUTH_SOCK=.*$/d' %s" % bashrc_file
|
||||
delete_line_cmd += " && sed -i '/^\\s*export\\s*SSH_AGENT_PID=.*$/d' %s" % bashrc_file
|
||||
delete_line_cmd += " && sed -i '/#OM$/d' %s" % DefaultValue.SSH_AUTHORIZED_KEYS
|
||||
delete_line_cmd += " && sed -i '/#OM$/d' %s" % DefaultValue.SSH_KNOWN_HOSTS
|
||||
delete_shell_cmd = " && rm -rf %s" % tmp_path
|
||||
@ -919,13 +953,31 @@ class PostUninstallImpl:
|
||||
CmdExecutor.execCommandLocally(cmd % kill_ssh_agent_cmd)
|
||||
self.logger.debug("Delete root mutual trust successfully.")
|
||||
|
||||
def cleanLocalBackupScript(self):
|
||||
"""
|
||||
function: clean gauss_om script
|
||||
"""
|
||||
# clean root script path
|
||||
if os.path.exists(self.gauss_om_path):
|
||||
FileUtil.removeDirectory(self.gauss_om_path)
|
||||
self.logger.log("Successfully cleaned local gauss_om.")
|
||||
self.logger.log("clean over.")
|
||||
return
|
||||
# if /root/gauss_om has no files, delete it.
|
||||
if not os.listdir(self.gauss_om_path):
|
||||
FileUtil.removeDirectory(self.gauss_om_path)
|
||||
self.logger.log("Successfully cleaned local gauss_om.")
|
||||
self.logger.log("clean over.")
|
||||
return
|
||||
self.logger.log("clean over.")
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.logger.debug(
|
||||
"gs_postuninstall execution takes %s steps in total"
|
||||
% ClusterCommand.countTotalSteps("gs_postuninstall"))
|
||||
local_host = NetUtil.GetHostIpOrName()
|
||||
if (self.mpprcFile is not None and self.mpprcFile != ""):
|
||||
if (self.mpprcFile is not None and self.mpprcFile != "" and os.path.exists(self.mpprcFile)):
|
||||
os_profile = self.mpprcFile
|
||||
else:
|
||||
os_profile = ClusterConstants.ETC_PROFILE
|
||||
@ -941,8 +993,14 @@ class PostUninstallImpl:
|
||||
self.cleanMpprcFile()
|
||||
self.cleanScript()
|
||||
self.setOrCleanGphomeEnv(setGphomeenv=False)
|
||||
self.delet_root_mutual_trust(local_host, path)
|
||||
self.logger.log("Successfully cleaned environment.")
|
||||
if os.path.exists(self.gauss_om_path):
|
||||
self.cleanOthernodesBackupScript()
|
||||
self.delet_root_mutual_trust(local_host, path)
|
||||
self.cleanLocalBackupScript()
|
||||
else:
|
||||
self.delet_root_mutual_trust(local_host, path)
|
||||
self.logger.log("clean over.")
|
||||
except Exception as e:
|
||||
self.logger.logExit(str(e))
|
||||
sys.exit(0)
|
||||
|
@ -2696,74 +2696,78 @@ Common options:
|
||||
str(no_install_soft_list))
|
||||
self.logger.debug("Successfully check OS software.")
|
||||
|
||||
def separate_root_scripts(self):
|
||||
def backup_om_scripts(self):
|
||||
"""
|
||||
fix packgae path permission and owner
|
||||
:return:
|
||||
"""
|
||||
package_path = get_package_path()
|
||||
om_root_path = os.path.dirname(package_path)
|
||||
if om_root_path == DefaultValue.ROOT_SCRIPTS_PATH or not self.current_user_root:
|
||||
om_backup_path = os.path.dirname(package_path)
|
||||
check_backup_path = os.path.join("/home", self.user, "gauss_om")
|
||||
if om_backup_path == check_backup_path or not self.current_user_root:
|
||||
return
|
||||
|
||||
self.logger.log("Separate om root scripts.")
|
||||
self.logger.debug("Create om root path.")
|
||||
# /root/gauss_om/user_name
|
||||
dest_path = os.path.join(DefaultValue.ROOT_SCRIPTS_PATH, self.user)
|
||||
self.logger.log("Backup om scripts.")
|
||||
self.logger.debug("Create backup_om path.")
|
||||
# /home/user/gauss_om/script
|
||||
dest_path = os.path.join("/home", self.user, "gauss_om")
|
||||
if os.path.exists(dest_path):
|
||||
shutil.rmtree(dest_path)
|
||||
os.makedirs(dest_path)
|
||||
FileUtil.changeOwner("root", dest_path)
|
||||
# Change owner to appropriate user
|
||||
FileUtil.changeOwner(self.user, 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)
|
||||
# cp cgroup to /home/user/gauss_om/script
|
||||
self.logger.debug("cp cgroup to /home/user/gauss_om/script.")
|
||||
backup_lib_dir = os.path.join(dest_path, "lib")
|
||||
backup_bin_dir = os.path.join(dest_path, "bin")
|
||||
FileUtil.createDirectory(backup_lib_dir, mode=DefaultValue.KEY_DIRECTORY_MODE)
|
||||
FileUtil.createDirectory(backup_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)
|
||||
cp_cmd = "cp -rf %s %s; cp -rf %s %s" % (libcgroup_dir, backup_lib_dir, cgroup_exe_dir, backup_bin_dir)
|
||||
CmdExecutor.execCommandLocally(cp_cmd)
|
||||
|
||||
# cp $GPHOME script lib to /root/gauss_om/xxx
|
||||
# cp $GPHOME script lib to /home/user/gauss_om/
|
||||
cmd = ("cp -rf %s/script %s/lib %s/version.cfg %s"
|
||||
% (self.clusterToolPath, self.clusterToolPath,
|
||||
self.clusterToolPath, dest_path))
|
||||
CmdExecutor.execCommandLocally(cmd)
|
||||
root_scripts = ["gs_postuninstall", "gs_preinstall",
|
||||
|
||||
backup_scripts = ["gs_postuninstall", "gs_preinstall",
|
||||
"gs_checkos"]
|
||||
common_scripts = ["gs_sshexkey", "killall", "gs_checkperf"]
|
||||
# the script files are not stored in the env path
|
||||
not_in_env_scripts = ["gs_expansion"]
|
||||
root_save_files = root_scripts + common_scripts
|
||||
self.logger.debug("Delete user scripts in om root path.")
|
||||
# delete user scripts in om root path
|
||||
om_root_path = os.path.join(dest_path, "script")
|
||||
root_om_files = os.listdir(om_root_path)
|
||||
for root_file in root_om_files:
|
||||
if root_file.startswith("gs_"):
|
||||
if root_file not in root_save_files:
|
||||
FileUtil.removeFile("%s/%s" % (om_root_path, root_file))
|
||||
backup_save_files = backup_scripts + common_scripts
|
||||
self.logger.debug("Delete user scripts in om backup_om path.")
|
||||
# delete user scripts in om backup_om path
|
||||
om_backup_path = os.path.join(dest_path, "script")
|
||||
backup_om_files = os.listdir(om_backup_path)
|
||||
for backup_file in backup_om_files:
|
||||
if backup_file.startswith("gs_"):
|
||||
if backup_file not in backup_save_files:
|
||||
FileUtil.removeFile("%s/%s" % (om_backup_path, backup_file))
|
||||
FileUtil.changeMode(DefaultValue.KEY_DIRECTORY_MODE,
|
||||
dest_path, recursive=True)
|
||||
dest_path, recursive=True)
|
||||
self.logger.debug("Set user scripts in om user path.")
|
||||
|
||||
self.logger.debug("Delete root scripts in om user path.")
|
||||
|
||||
# set om root script path
|
||||
# set om user script path
|
||||
userProfile = self.getUserProfile()
|
||||
if userProfile is ClusterConstants.ETC_PROFILE:
|
||||
FileUtil.writeFile(userProfile, ["export PATH=$PATH:%s" % om_root_path])
|
||||
FileUtil.writeFile(userProfile, ["export PATH=$PATH:%s" % dest_path])
|
||||
else:
|
||||
FileUtil.writeFile(userProfile, ["export PATH=%s:$PATH" % om_root_path])
|
||||
# delete root scripts in GPHOME
|
||||
FileUtil.writeFile(userProfile, ["export PATH=%s/script:$PATH" % dest_path])
|
||||
|
||||
# delete backup_om scripts in GPHOME
|
||||
om_user_path = os.path.join(self.clusterToolPath, "script")
|
||||
user_om_files = os.listdir(om_user_path)
|
||||
for user_file in user_om_files:
|
||||
if user_file.startswith("gs_"):
|
||||
if user_file in root_scripts or user_file in not_in_env_scripts:
|
||||
if user_file in backup_scripts or user_file in not_in_env_scripts:
|
||||
FileUtil.removeFile("%s/%s" % (om_user_path, user_file))
|
||||
self.logger.debug("Delete cluster decompress package in root path.")
|
||||
FileUtil.changeOwner(self.user, dest_path, recursive=True)
|
||||
self.logger.debug("Delete cluster decompress package in user path.")
|
||||
|
||||
def fixop_xml_and_mpp_file(self):
|
||||
"""
|
||||
@ -2914,7 +2918,7 @@ Common options:
|
||||
:return:
|
||||
"""
|
||||
self.fix_owner_and_permission()
|
||||
self.separate_root_scripts()
|
||||
self.backup_om_scripts()
|
||||
|
||||
def dss_init(self):
|
||||
'''
|
||||
|
@ -135,7 +135,7 @@ class Postuninstall(LocalBaseOM):
|
||||
# and get the right profile
|
||||
# we can not check mppenvfile exists here
|
||||
mppenvFile = EnvUtil.getEnv(DefaultValue.MPPRC_FILE_ENV)
|
||||
if mppenvFile != "" and mppenvFile is not None:
|
||||
if mppenvFile != "" and mppenvFile is not None and os.path.exists(mppenvFile):
|
||||
self.userProfile = mppenvFile
|
||||
else:
|
||||
self.userProfile = ProfileFile.get_user_bashrc(self.user)
|
||||
@ -480,17 +480,15 @@ class Postuninstall(LocalBaseOM):
|
||||
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)
|
||||
|
||||
# mkdir gauss_om dir
|
||||
gaussom_lib_dir = "/home/%s/gauss_om/lib/" % self.user
|
||||
gaussom_bin_dir = "/home/%s/gauss_om/bin/" % 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)
|
||||
cmd = "export LD_LIBRARY_PATH=%s:\$LD_LIBRARY_PATH && %s/gs_cgroup -d -U %s" % (gaussom_lib_dir, gaussom_bin_dir, self.user)
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
if status != 0:
|
||||
self.logger.logExit(
|
||||
"Error: Failed to delete cgroup "
|
||||
"Error: Failed to delete cgroup "
|
||||
"cmd:%s. Error: \n%s" % (cmd, output))
|
||||
self.logger.debug("Successfully cleaned user cgroup.")
|
||||
|
||||
@ -544,15 +542,6 @@ class Postuninstall(LocalBaseOM):
|
||||
if os.path.exists(scriptPath):
|
||||
FileUtil.removeDirectory(scriptPath)
|
||||
|
||||
# clean root script path
|
||||
root_script_path = os.path.join(DefaultValue.ROOT_SCRIPTS_PATH,
|
||||
self.user)
|
||||
if os.path.exists(root_script_path):
|
||||
FileUtil.removeDirectory(root_script_path)
|
||||
# if /root/gauss_om has no files, delete it.
|
||||
if not os.listdir(DefaultValue.ROOT_SCRIPTS_PATH):
|
||||
FileUtil.removeDirectory(DefaultValue.ROOT_SCRIPTS_PATH)
|
||||
|
||||
# clean others
|
||||
if os.path.exists(self.clusterToolPath):
|
||||
FileUtil.cleanDirectoryContent(self.clusterToolPath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user