def parseCommandLine(): """ function: Parse command line and save to global variable input : NA output: NA """ try: (opts, args) = getopt.getopt(sys.argv[1:], "t:U:l:", ["help"]) except Exception as e: # print help information usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) # parse parameter for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-t"): g_opts.action = value elif (key == "-l"): g_opts.logFile = value elif (key == "-U"): g_opts.user = value Parameter.checkParaVaild(key, value)
def backupConf(self, appPath, user, host, envfile, sshTool): """ backup the configuration file (postgresql.conf and pg_hba.conf) The Backup.py can do this """ self.logger.log( "[gs_dropnode]Start to backup parameter config file on %s." % host) tmpPath = '/tmp/gs_dropnode_backup' + \ str(datetime.datetime.now().strftime('%Y%m%d%H%M%S')) backupPyPath = os.path.join(appPath, './script/local/Backup.py') cmd = "(find /tmp -type d | grep gs_dropnode_backup | xargs rm -rf;" \ "if [ ! -d '%s' ]; then mkdir -p '%s' -m %s;fi)" \ % (tmpPath, tmpPath, DefaultValue.KEY_DIRECTORY_MODE) sshTool.executeCommand(cmd, "", DefaultValue.SUCCESS, [host], envfile) logfile = os.path.join(tmpPath, 'gs_dropnode_call_Backup_py.log') cmd = "python3 %s -U %s -P %s -p --nodeName=%s -l %s" \ % (backupPyPath, user, tmpPath, host, logfile) (statusMap, output) = sshTool.getSshStatusOutput(cmd, [host], envfile) if statusMap[host] != 'Success': self.logger.debug( "[gs_dropnode]Backup parameter config file failed." + output) GaussLog.exitWithError(ErrorCode.GAUSS_358["GAUSS_35809"]) self.logger.log( "[gs_dropnode]End to backup parameter config file on %s." % host) return '%s/parameter_%s.tar' % (tmpPath, host)
def parseBackupFile(self, host, backupfile, dnId, replstr, sshTool, envfile): """ parse the backup file eg.parameter_host.tar to get the value for rollback """ self.logger.log( "[gs_dropnode]Start to parse backup parameter config file on %s." % host) resultDict = {'rollbackReplStr': '', 'syncStandbyStr': ''} backupdir = os.path.dirname(backupfile) cmd = "tar xf %s -C %s;grep -o '^replconninfo.*' %s/%s/%s_postgresql.conf;" \ "grep -o '^synchronous_standby_names.*' %s/%s/%s_postgresql.conf;" \ % ( backupfile, backupdir, backupdir, 'parameter_' + host, dnId[3:], backupdir, 'parameter_' + host, dnId[3:]) (statusMap, output) = sshTool.getSshStatusOutput(cmd, [host], envfile) if statusMap[host] != 'Success': self.logger.log( "[gs_dropnode]Parse backup parameter config file failed:" + output) GaussLog.exitWithError(ErrorCode.GAUSS_358["GAUSS_35809"]) for i in replstr: tmp_v = 'replconninfo' + i s = output.index(tmp_v) e = output.find('\n', s, len(output)) resultDict['rollbackReplStr'] += output[s:e].split("'")[-2] + '|' s = output.index('synchronous_standby_names') resultDict['syncStandbyStr'] = output[s:].split("'")[-2] self.logger.log( "[gs_dropnode]End to parse backup parameter config file %s." % host) return resultDict
def preInstallOnHosts(self): """ execute preinstall step """ self.logger.debug("Start to preinstall database step.\n") newBackIps = self.context.newHostList newHostNames = [] for host in newBackIps: newHostNames.append(self.context.backIpNameMap[host]) envfile = self.envFile tempXmlFile = "%s/clusterconfig.xml" % self.tempFileDir preinstallCmd = "{softpath}/script/gs_preinstall -U {user} -G {group} \ -X {xmlfile} --sep-env-file={envfile} \ --non-interactive 2>&1\ ".format(softpath=self.context.packagepath,user=self.user, group=self.group,xmlfile=tempXmlFile,envfile=envfile) sshTool = SshTool(newHostNames) status, output = sshTool.getSshStatusOutput(preinstallCmd , [], envfile) statusValues = status.values() if STATUS_FAIL in statusValues: GaussLog.exitWithError(output) self.logger.debug("End to preinstall database step.\n")
def restartInstance(self): if self.context.flagOnlyPrimary: self.logger.log("[gs_dropnode]Remove the dynamic conf.") dynamicConfigPath = "%s/bin/cluster_dynamic_config" % self.appPath try: os.unlink(dynamicConfigPath) except FileNotFoundError: pass flag = input( "Only one primary node is left." "It is recommended to restart the node." "\nDo you want to restart the primary node now (yes/no)? ") count_f = 2 while count_f: if (flag.upper() != "YES" and flag.upper() != "NO" and flag.upper() != "Y" and flag.upper() != "N"): count_f -= 1 flag = input("Please type 'yes' or 'no': ") continue break if flag.upper() != "YES" and flag.upper() != "Y": GaussLog.exitWithError(ErrorCode.GAUSS_358["GAUSS_35805"] % flag.upper()) sshTool = SshTool([self.localhostname]) for i in self.context.hostMapForExist[ self.localhostname]['datadir']: self.commonOper.stopInstance(self.localhostname, sshTool, i, self.userProfile) self.commonOper.startInstance(i, self.userProfile) self.cleanSshToolFile(sshTool) else: pass
def run(self): """ function: run method """ try: # check timeout time. # Notice: time_out is not supported under TP branch self.checkTimeout() # check if have done preinstall for this user on every node self.checkGaussenvFlag() # check the clueter status self.checkClusterStatus() # creating the backup directory self.prepareBackDir() # Check time consistency(only TP use it must less 2s) self.checkTimeConsistency() # install clueter self.context.logger.log("begin deploy..") self.doDeploy() self.context.logger.log("end deploy..") # close the log file self.context.logger.closeLog() except Exception as e: GaussLog.exitWithError(str(e))
def getActionParameterValue(self, module): """ function: get the action value input : parameter_list output: NA """ actions = [] getMode = False if (module in special_list): if (sys.argv[1:] == []): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50014"] % module) if (sys.argv[1:][-1] == "-t"): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % \ "t" + " option -t requires argument.") for n, value in enumerate(sys.argv[1:]): if (sys.argv[1:][n - 1] == "-t"): actions.append(value) if (len(actions) != 1): GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50006"] % actions[0]) self.action = value if self.action == "": GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % "t" + ".") if ((module == "gsom" and not self.action in action_om) or (module == "upgradectl" and not self.action in action_upgradectl)): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "t")
def parseCommandLine(): """ function: parse command line """ try: opts, args = getopt.getopt(sys.argv[1:], "U:t:h", ["help"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if len(args) > 0: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if key == "-h" or key == "--help": usage() sys.exit(0) elif key == "-t": g_opts.action = value elif key == "-U": g_opts.clusterUser = value
def stop(self, stopMode="", time_out=300): """ """ cmd = "%s/gs_ctl stop -D %s " % (self.binPath, self.instInfo.datadir) if not self.isPidFileExist(): cmd += " -m immediate" else: # check stop mode if stopMode != "": cmd += " -m %s" % stopMode cmd += " -t %s" % time_out self.logger.debug("stop cmd = %s" % cmd) (status, output) = subprocess.getstatusoutput(cmd) if status != 0: raise Exception(ErrorCode.GAUSS_516["GAUSS_51610"] % "instance" + " Error: \n%s." % output) if output.find("No such process") > 0: cmd = "ps c -eo pid,euid,cmd | grep gaussdb | grep -v grep | " \ "awk '{if($2 == curuid && $1!=\"-n\") " \ "print \"/proc/\"$1\"/cwd\"}' curuid=`id -u`|" \ " xargs ls -l |awk '{if ($NF==\"%s\") print $(NF-2)}' | " \ "awk -F/ '{print $3 }'" % (self.instInfo.datadir) (status, rightpid) = subprocess.getstatusoutput(cmd) if rightpid or status != 0: GaussLog.exitWithError(output)
def checkAllStandbyState(self): """ check all standby state whether switchover is happening """ for hostNameLoop in self.context.hostMapForDel.keys(): if hostNameLoop not in self.context.failureHosts: sshtool_host = SshTool([hostNameLoop]) for i in self.context.hostMapForDel[hostNameLoop]['datadir']: # check whether switchover/failover is happening if not self.commonOper.checkStandbyState( hostNameLoop, i, sshtool_host, self.userProfile, True): GaussLog.exitWithError( ErrorCode.GAUSS_358["GAUSS_35808"] % hostNameLoop) self.commonOper.stopInstance(hostNameLoop, sshtool_host, i, self.userProfile) self.cleanSshToolFile(sshtool_host) for hostNameLoop in self.context.hostMapForExist.keys(): sshtool_host = SshTool([hostNameLoop]) for i in self.context.hostMapForExist[hostNameLoop]['datadir']: # check whether switchover/failover is happening if not self.commonOper.checkStandbyState( hostNameLoop, i, sshtool_host, self.userProfile): GaussLog.exitWithError(ErrorCode.GAUSS_358["GAUSS_35808"] % hostNameLoop) self.cleanSshToolFile(sshtool_host)
def run(self): try: self.parseCommandLine() self.checkParameter() self.initGlobals() except Exception as e: GaussLog.exitWithError(str(e)) try: if (self.action == ACTION_CLEAN_SYSLOG_CONFIG): self.cleanWarningConfig() elif (self.action == ACTION_CLEAN_TOOL_ENV): self.cleanEnvSoftware() elif (self.action == ACTION_CHECK_UNPREINSTALL): self.checkUnPreInstall() elif (self.action == ACTION_CLEAN_GAUSS_ENV): self.cleanGaussEnv() elif (self.action == ACTION_DELETE_GROUP): self.cleanGroup() elif (self.action == ACTION_CLEAN_DEPENDENCY): self.cleanScript() elif (self.action == ACTION_CLEAN_ENV): self.cleanEnv() elif (self.action == ACTION_CLEAN_INSTANCE_PATHS): self.cleanPath() else: self.logger.logExit(ErrorCode.GAUSS_500["GAUSS_50000"] % self.action) except Exception as e: self.logger.logExit(str(e))
def parseCommandLine(): """ """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:G:l:?", ["help", "dws_mode", "vc_mode"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if (key == "-?" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.clusterUser = value elif (key == "-P"): g_opts.dbInitParams.append(value) elif (key == "-l"): g_opts.logFile = os.path.realpath(value) elif (key == "--dws_mode"): g_opts.dws_mode = True elif (key == "--vc_mode"): g_opts.vc_mode = True Parameter.checkParaVaild(key, value)
def checkRestoreDir(restoreDir): """ function: check restore directory input : NA output: NA """ if (restoreDir == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % "P" + ".")
def checkTmpBackupDir(tmpBackupDir): """ function: check tmp backup directory input : NA output: NA """ if (tmpBackupDir == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'P' + ".")
def checkUserParameter(): """ function: check user parameter input : NA output: NA """ if (g_clusterUser == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".")
def generateClusterStaticFile(self): """ generate static_config_files and send to all hosts """ self.logger.debug("Start to generate and send cluster static file.\n") primaryHosts = self.getPrimaryHostName() command = "gs_om -t generateconf -X %s --distribute" % self.context.xmlFile sshTool = SshTool([primaryHosts]) resultMap, outputCollect = sshTool.getSshStatusOutput( command, [primaryHosts], self.envFile) self.logger.debug(outputCollect) self.cleanSshToolFile(sshTool) nodeNameList = self.context.nodeNameList for hostName in nodeNameList: hostSsh = SshTool([hostName]) toolPath = self.context.clusterInfoDict["toolPath"] appPath = self.context.clusterInfoDict["appPath"] srcFile = "%s/script/static_config_files/cluster_static_config_%s" \ % (toolPath, hostName) if not os.path.exists(srcFile): GaussLog.exitWithError("Generate static file [%s] not found." \ % srcFile) targetFile = "%s/bin/cluster_static_config" % appPath hostSsh.scpFiles(srcFile, targetFile, [hostName], self.envFile) self.cleanSshToolFile(hostSsh) self.logger.debug("End to generate and send cluster static file.\n") time.sleep(10) # Single-node database need start cluster after expansion if self.isSingleNodeInstance: self.logger.debug("Single-Node instance need restart.\n") self.commonGsCtl.queryOmCluster(primaryHosts, self.envFile) # if primary database not normal, restart it primaryHost = self.getPrimaryHostName() dataNode = self.context.clusterInfoDict[primaryHost]["dataNode"] insType, dbStat = self.commonGsCtl.queryInstanceStatus( primaryHost, dataNode, self.envFile) if insType != MODE_PRIMARY: self.commonGsCtl.startInstanceWithMode(primaryHost, dataNode, MODE_PRIMARY, self.envFile) # if stat if not normal,rebuild standby database standbyHosts = self.context.newHostList for host in standbyHosts: hostName = self.context.backIpNameMap[host] dataNode = self.context.clusterInfoDict[hostName]["dataNode"] insType, dbStat = self.commonGsCtl.queryInstanceStatus( hostName, dataNode, self.envFile) if dbStat != STAT_NORMAL: self.commonGsCtl.startInstanceWithMode( hostName, dataNode, MODE_STANDBY, self.envFile) self.commonGsCtl.startOmCluster(primaryHosts, self.envFile)
def checkUserAndGroupExists(self): """ check system user and group exists and be same on primary and standby nodes """ inputUser = self.user inputGroup = self.group user_group_id = "" isUserExits = False localHost = socket.gethostname() for user in pwd.getpwall(): if user.pw_name == self.user: user_group_id = user.pw_gid isUserExits = True break if not isUserExits: GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35704"] \ % ("User", self.user, localHost)) isGroupExits = False group_id = "" for group in grp.getgrall(): if group.gr_name == self.group: group_id = group.gr_gid isGroupExits = True if not isGroupExits: GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35704"] \ % ("Group", self.group, localHost)) if user_group_id != group_id: GaussLog.exitWithError("User [%s] is not in the group [%s]."\ % (self.user, self.group)) hostNames = self.context.newHostList envfile = self.envFile sshTool = SshTool(hostNames) #get username in the other standy nodes getUserNameCmd = "cat /etc/passwd | grep -w %s" % inputUser resultMap, outputCollect = sshTool.getSshStatusOutput( getUserNameCmd, [], envfile) for hostKey in resultMap: if resultMap[hostKey] == STATUS_FAIL: self.cleanSshToolFile(sshTool) GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35704"] \ % ("User", self.user, hostKey)) #get groupname in the other standy nodes getGroupNameCmd = "cat /etc/group | grep -w %s" % inputGroup resultMap, outputCollect = sshTool.getSshStatusOutput( getGroupNameCmd, [], envfile) for hostKey in resultMap: if resultMap[hostKey] == STATUS_FAIL: self.cleanSshToolFile(sshTool) GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35704"] \ % ("Group", self.group, hostKey)) self.cleanSshToolFile(sshTool)
def checkParameterEmpty(parameter, parameterName): """ function: check parameter empty input : parameter, parameterName output: NA """ if parameter == "": GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % parameterName + ".")
def checkUserExist(): """ function: check user exists input : NA output: NA """ if (g_clusterUser == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % "U" + ".") DefaultValue.checkUser(g_clusterUser, False)
def checkRestorePara(restorePara, restoreBin): """ function: check restore parameter input : NA output: NA """ if not restorePara and not restoreBin: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % "p or -b" + ".")
def checkBackupPara(backupPara, backupBin): """ function: check -P and -b parameter input : NA output: NA """ if not backupPara and not backupBin: GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50001"] % 'P or -b' + ".")
def checkLocalModeOnStandbyHosts(self): """ expansion the installed standby node. check standby database. 1. if the database is normal 2. if the databases version are same before existing and new """ standbyHosts = self.context.newHostList envfile = self.envFile self.logger.log("Checking the database with locale mode.") for host in standbyHosts: hostName = self.context.backIpNameMap[host] dataNode = self.context.clusterInfoDict[hostName]["dataNode"] insType, dbStat = self.commonGsCtl.queryInstanceStatus( hostName, dataNode, self.envFile) if insType not in (MODE_PRIMARY, MODE_STANDBY, MODE_NORMAL): GaussLog.exitWithError( ErrorCode.GAUSS_357["GAUSS_35703"] % (hostName, self.user, dataNode, dataNode)) allHostIp = [] allHostIp.append(self.context.localIp) versionDic = {} for hostip in standbyHosts: allHostIp.append(hostip) sshTool = SshTool(allHostIp) #get version in the nodes getversioncmd = "gaussdb --version" resultMap, outputCollect = sshTool.getSshStatusOutput( getversioncmd, [], envfile) self.cleanSshToolFile(sshTool) versionLines = outputCollect.splitlines() for verline in versionLines: if verline[0:9] == '[SUCCESS]': ipKey = verline[10:-1] continue else: versionStr = "".join(verline) preVersion = versionStr.split(' ') versionInfo = preVersion[4] versionDic[ipKey] = versionInfo[:-2] for hostip in versionDic: if hostip == self.context.localIp: versionCompare = "" versionCompare = versionDic[hostip] else: if versionDic[hostip] == versionCompare: continue else: GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35705"] \ %(hostip, versionDic[hostip])) self.logger.log("Successfully checked the database with locale mode.")
def main(): """ main function """ try: stop = Stop() stop.parseCommandLine() stop.init() stop.doStop() except Exception as e: GaussLog.exitWithError(ErrorCode.GAUSS_536["GAUSS_53609"] % str(e))
def checkLogFile(logFile): """ function: check log file input : NA output: NA """ if (logFile == ""): logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE, g_clusterUser, "") if (not os.path.isabs(logFile)): GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50213"] % "log")
def change_user(self): if os.getuid() == 0: user = self.user try: pw_record = pwd.getpwnam(user) except CheckException: GaussLog.exitWithError(ErrorCode.GAUSS_503["GAUSS_50300"] % user) user_uid = pw_record.pw_uid user_gid = pw_record.pw_gid os.setgid(user_gid) os.setuid(user_uid)
def checkParameters(self): """ function: Check input parameters input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "t:U:R:l:X:M:T", ["help", "delete-data"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) for key, value in opts: if (key == "-U"): self.user = value elif (key == "-R"): self.installPath = value elif (key == "-l"): self.logFile = value elif (key == "--help"): self.usage() sys.exit(0) elif (key == "-T"): self.installflag = True elif key == "--delete-data": self.keepData = False elif key == "-M": self.method = value elif key == "-t": self.action = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if (self.user == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") if (self.installPath == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'R' + ".") self.mpprcFile = DefaultValue.getMpprcFile() if (self.logFile == ""): self.logFile = DefaultValue.getOMLogPath( DefaultValue.LOCAL_LOG_FILE, self.user, self.installPath)
def checkParameter(): """ function: check install parameter input : NA output: NA """ if g_opts.action == "": GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 't' + '.') if (g_opts.action != ACTION_INSTALL_CLUSTER and g_opts.action != ACTION_PREPARE_CONFIG_CLUSTER and g_opts.action != ACTION_INIT_INSTNACE and g_opts.action != ACTION_CONFIG_CLUSTER and g_opts.action != ACTION_START_CLUSTER and g_opts.action != ACTION_CLEAN_TEMP_FILE and g_opts.action != ACTION_BUILD_STANDBY and g_opts.action != ACTION_BUILD_CASCADESTANDBY): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "t") if (g_opts.clusterConfig != "" and not os.path.exists(g_opts.clusterConfig)): GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50201"] % g_opts.clusterConfig) if (g_opts.logPath != "" and not os.path.exists(g_opts.logPath) and not os.path.isabs(g_opts.logPath)): GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50219"] % g_opts.logPath) if (g_opts.static_config_file != "" and not os.path.isfile(g_opts.static_config_file)): GaussLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50219"] % g_opts.static_config_file) # check mpprc file path g_opts.mpprcFile = DefaultValue.getMpprcFile() g_opts.logger = GaussLog(g_opts.logFile) checkParameterEmpty(g_opts.user, "U") g_opts.installPath = os.path.normpath(g_opts.installPath) g_opts.installPath = os.path.realpath(g_opts.installPath) g_opts.logger.log("Using " + g_opts.user + ":" + g_opts.group + " to install database.") g_opts.logger.log("Using installation program path : " + g_opts.installPath) if g_opts.logFile == "": g_opts.logFile = DefaultValue.getOMLogPath( DefaultValue.LOCAL_LOG_FILE, g_opts.user, "", g_opts.clusterConfig) if g_opts.alarmComponent == "": g_opts.alarmComponent = DefaultValue.ALARM_COMPONENT_PATH
def changeUser(self): user = self.user try: pw_record = pwd.getpwnam(user) except Exception: GaussLog.exitWithError(ErrorCode.GAUSS_503["GAUSS_50300"] % user) user_name = pw_record.pw_name user_uid = pw_record.pw_uid user_gid = pw_record.pw_gid env = os.environ.copy() os.setgid(user_gid) os.setuid(user_uid)
def parseCommandLine(): """ function: parseCommandLine input: NA output: NA """ try: paraLine = sys.argv[1] paraLine = DefaultValue.encodeParaline(paraLine, DefaultValue.BASE_DECODE) paraLine = paraLine.strip() paraList = paraLine.split("*==SYMBOL==*") opts, args = getopt.getopt( paraList[1:], "U:C:D:T:P:l:hX:", ["help", "alarm=", "gucXml", "vc_mode", "dws-mode"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.clusterUser = value elif (key == "-D"): g_opts.dataGucParams.append(value) elif (key == "-T"): g_opts.configType = value elif (key == "-P"): g_opts.clusterStaticConfigFile = value elif (key == "-l"): g_opts.logFile = os.path.realpath(value) elif (key == "--alarm"): g_opts.alarmComponent = value elif (key == "--gucXml"): g_opts.gucXml = True elif (key == "--vc_mode"): g_opts.vcMode = True elif (key == "--dws-mode"): g_opts.dws_mode = True elif key == "-X": g_opts.clusterConf = os.path.realpath(value) Parameter.checkParaVaild(key, value)
def main(): """ main function """ try: start = Start() start.parseCommandLine() start.init() except Exception as e: GaussLog.exitWithError(ErrorCode.GAUSS_536["GAUSS_53608"] % str(e)) try: start.doStart() except Exception as e: GaussLog.exitWithError(str(e))