Example #1
0
    def __getLockFiles(self):
        files = []
        if(self.xmlFile == ""):
            tmp_dir = DefaultValue.getTmpDirFromEnv()
        else:
            tmp_dir = DefaultValue.getTmpDir(self.user, self.xmlFile)
            
        instances = []
        instances += self.dbNodeInfo.gtms
        instances += self.dbNodeInfo.cmservers
        instances += self.dbNodeInfo.coordinators
        instances += self.dbNodeInfo.datanodes
        instances += self.dbNodeInfo.datanodes
        instances += self.dbNodeInfo.cmagents
        
        for dbInst in instances:
            if (dbInst.datadir not in self.Instancedirs):
                continue

            pgsql = ".s.PGSQL.%d" % dbInst.port
            pgsql_lock = ".s.PGSQL.%d.lock" % dbInst.port
            files.append(os.path.join(tmp_dir, pgsql))
            files.append(os.path.join(tmp_dir, pgsql_lock))

        for cooInst in self.dbNodeInfo.coordinators:
            if (cooInst.datadir not in self.Instancedirs):
                continue

            pgpool = ".s.PGPOOL.%d" % cooInst.haPort
            pgpool_lock = ".s.PGPOOL.%d.lock" % cooInst.haPort
            files.append(os.path.join(tmp_dir, pgpool))
            files.append(os.path.join(tmp_dir, pgpool_lock))

        return files
Example #2
0
def writePid(user):
    """
    Write pid to file
    """
    pid = "%d" % os.getpid()
    tmpDir = DefaultValue.getTmpDirFromEnv()
    clusterLockFilePath = "%s/%s" % (tmpDir, DefaultValue.CLUSTER_LOCK_PID)
    PlatformCommand.WriteInfoToFile(clusterLockFilePath, pid)
Example #3
0
    def __init__(self, installPath, nodename, datadirs):
        """
        Constructor
        """
        self.installPath = installPath
        self.nodename = nodename
        self.datadirs = datadirs

        self.__user = ""
        self.__group = ""

        self.__logDir = DefaultValue.getOMLogPath(DefaultValue.GURRENT_DIR_FILE, "", installPath)
Example #4
0
def checkParameter():
    """
    Check parameter for create os user
    """
    if (g_opts.userInfo == ""):
        GaussLog.exitWithError("Parameter input error, need '-U' parameter.")
        
    strList = g_opts.userInfo.split(":")
    if (len(strList) != 2):
        GaussLog.exitWithError("Parameter input error: -U " + g_opts.userInfo)
    if (strList[0] == "" or strList[1] == ""):
        GaussLog.exitWithError("Parameter input error: -U " + g_opts.userInfo)
    g_opts.user = strList[0]
    g_opts.group = strList[1]
    
        
    if (g_opts.logFile == ""):
        g_opts.logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, g_opts.user, "")
        
    if (not os.path.isabs(g_opts.logFile)):
        GaussLog.exitWithError("Parameter input error, log path need absolute path.")
Example #5
0
            try:
                time_out = int(value)
            except Exception, e:
                GaussLog.exitWithError("Parameter input error: %s" % str(e))
        elif (key == "-U"):
            user = value
        elif (key == "-l"):
            logFile = value
        else:
            GaussLog.exitWithError("Parameter input error, unknown options %s." % key)
            
    if (user == ""):
        GaussLog.exitWithError("Parameter input error, need '-U' parameter.")
        
    if (logFile == ""):
        logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, user, "")
    
    writePid(user)
    global g_logger
    g_logger = GaussLog(logFile)
    
    if (time_out <= 0):
        time_out = 1800
    endTime = datetime.now() + timedelta(seconds=time_out)

    connList = ClusterCommand.readCooConnections(user)
    if (len(connList) == 0):
        raise Exception("There is no coordinator to connect!")
    ip = connList[0][0]
    port = connList[0][1]
    
Example #6
0
    def doPrivateConfigSet(self, localInst, configFile):
        """
        """
        configFile = os.path.join(localInst.datadir, configFile)
        self.logger.debug("Set private config file: %s" % configFile)
        
        if (localInst.instanceRole == INSTANCE_ROLE_CMAGENT):
            self.modifyConfigItem(localInst, configFile, "log_dir", "%s/cm/cm_agent" % DefaultValue.getUserLogDirWithUser(self.user))
        elif (localInst.instanceRole == INSTANCE_ROLE_COODINATOR):
            self.modifyConfigItem(localInst, configFile, "listen_addresses", "'localhost,%s'" % ",".join(localInst.listenIps))
            self.modifyConfigItem(localInst, configFile, "port", str(localInst.port))
            self.modifyConfigItem(localInst, configFile, "pgxc_node_name", "'cn_%d'" % localInst.instanceId)
            self.modifyConfigItem(localInst, configFile, "pooler_port", str(localInst.haPort))
            self.modifyConfigItem(localInst, configFile, "log_directory", "'%s/pg_log/cn_%d'" % (DefaultValue.getUserLogDirWithUser(self.user), localInst.instanceId))
            self.modifyConfigItem(localInst, configFile, "audit_directory", "'%s/pg_audit/cn_%d'" % (DefaultValue.getUserLogDirWithUser(self.user), localInst.instanceId))
        elif(localInst.instanceRole == INSTANCE_ROLE_DATANODE):
            peerInsts = self.clusterInfo.getPeerInstance(localInst)
            if (len(peerInsts) != 2 and len(peerInsts) != 1):
                self.logger.logExit("Get peer instance failed!")
            masterInst = None
            standbyInst = None
            dummyStandbyInst = None
            nodename = ""
            for i in range(len(peerInsts)):
                if(peerInsts[i].instanceType == MASTER_INSTANCE):
                    masterInst = peerInsts[i]
                elif(peerInsts[i].instanceType == STANDBY_INSTANCE):
                    standbyInst = peerInsts[i]
                elif(peerInsts[i].instanceType == DUMMY_STANDBY_INSTANCE):
                    dummyStandbyInst = peerInsts[i]
                    
            if(localInst.instanceType == MASTER_INSTANCE):
                masterInst = localInst
                nodename = "dn_%d_%d" % (masterInst.instanceId, standbyInst.instanceId)
            elif(localInst.instanceType == STANDBY_INSTANCE):
                standbyInst = localInst
                nodename = "dn_%d_%d" % (masterInst.instanceId, standbyInst.instanceId)
            elif(localInst.instanceType == DUMMY_STANDBY_INSTANCE):
                dummyStandbyInst = localInst
                nodename = "dn_%d_%d" % (masterInst.instanceId, dummyStandbyInst.instanceId)

            self.modifyConfigItem(localInst, configFile, "listen_addresses", "'%s'" % ",".join(localInst.listenIps))
            self.modifyConfigItem(localInst, configFile, "port", str(localInst.port))
            self.modifyConfigItem(localInst, configFile, "pgxc_node_name", "'%s'" % nodename)
            self.modifyConfigItem(localInst, configFile, "log_directory", "'%s/pg_log/dn_%d'" % (DefaultValue.getUserLogDirWithUser(self.user), localInst.instanceId))  
            self.modifyConfigItem(localInst, configFile, "audit_directory", "'%s/pg_audit/dn_%d'" % (DefaultValue.getUserLogDirWithUser(self.user), localInst.instanceId))

            if(localInst.instanceType == MASTER_INSTANCE):
                self.modifyConfigItem(localInst, configFile, "replconninfo1", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                        (localInst.haIps[0], localInst.haPort, standbyInst.haIps[0], standbyInst.haPort))
                if(dummyStandbyInst != None):
                    self.modifyConfigItem(localInst, configFile, "replconninfo2", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                            (localInst.haIps[0], localInst.haPort, dummyStandbyInst.haIps[0], dummyStandbyInst.haPort))
            elif(localInst.instanceType == STANDBY_INSTANCE):
                self.modifyConfigItem(localInst, configFile, "replconninfo1", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                        (localInst.haIps[0], localInst.haPort, masterInst.haIps[0], masterInst.haPort))
                if(dummyStandbyInst != None):
                    self.modifyConfigItem(localInst, configFile, "replconninfo2", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                            (localInst.haIps[0], localInst.haPort, dummyStandbyInst.haIps[0], dummyStandbyInst.haPort))
            elif(localInst.instanceType == DUMMY_STANDBY_INSTANCE):
                self.modifyConfigItem(localInst, configFile, "replconninfo1", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                        (localInst.haIps[0], localInst.haPort, masterInst.haIps[0], masterInst.haPort))
                self.modifyConfigItem(localInst, configFile, "replconninfo2", "'localhost=%s localport=%d remotehost=%s remoteport=%d'" % 
                                        (localInst.haIps[0], localInst.haPort, standbyInst.haIps[0], standbyInst.haPort))
        else:
            self.logger.logExit("current instance role is invalid [%s %s]." % (localInst.datadir,  localInst,instanceRole))
Example #7
0
            usage()
            sys.exit(0)
        elif (key == "-X"):
            confFile = value
        elif (key == "-l"):
            logFile = value
        elif (key == "--target"):
            target = value
        else:
            GaussLog.exitWithError("Parameter input error, unknown options %s." % key)

    if (not os.path.isabs(confFile)):
        GaussLog.exitWithError("Parameter input error, configure file need absolute path.")
        
    if (logFile == ""):
        logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, "", "", confFile)
        
    if (not os.path.isabs(logFile)):
        GaussLog.exitWithError("Parameter input error, log file need absolute path.")
        
    config = DilatationConfig(logFile, "", confFile)
    if (target == "clean"):
        config.clean()
    elif (target == "restore"):
        config.restore()
    elif (target == "config"):
        config.config()
    elif (target == "check"):
        config.check()
    elif (target == "localstart"):
        config.localStart()
Example #8
0
def executeCommand():
    """
    """
    failedNodes = ""
    succeedNodes = ""
    try:
        command = (g_opts.cmd.strip()).split(" ")
        if len(command) > 1:
            GaussLog.exitWithError("Parameter -c input error, only need command.")
        checkCmd = "which %s" % command[0]
        (status, output) = g_sshTool.getSshStatusOutput(checkCmd)
        for node in status.keys():
            if status[node] != 0:
                failedNodes += "%s " % node
            else:
                succeedNodes += "%s " % node
        if failedNodes != "":
            GaussLog.exitWithError(
                "Command %s not exist or not have executable permissions on %s." % (command, failedNodes)
            )
        failedNodes = ""
        succeedNodes = ""
        executeCmd = g_opts.cmd + " " + g_opts.parameterlist
        #############################################################
        cmdFile = "%s/ClusterCall_%d.sh" % (DefaultValue.getTmpDirFromEnv(), os.getpid())
        cmdCreateFile = "touch %s" % cmdFile
        (status, output) = commands.getstatusoutput(cmdCreateFile)
        if status != 0:
            GaussLog.exitWithError("Touch file %s failed!" % cmdFile)

        cmdFileMod = "chmod 640 %s" % cmdFile
        (status, output) = commands.getstatusoutput(cmdFileMod)
        if status != 0:
            GaussLog.exitWithError("Chmod file %s failed!" % cmdFile)

        fp = open(cmdFile, "a")
        fp.write("#!/bin/sh")
        fp.write(os.linesep)
        fp.write("%s" % (executeCmd))
        fp.write(os.linesep)
        fp.flush()
        fp.close()

        ##############################################################
        cmdDir = DefaultValue.getTmpDirFromEnv()
        g_sshTool.scpFiles(cmdFile, cmdDir)
        cmdExecute = "sh %s" % cmdFile
        (status, output) = g_sshTool.getSshStatusOutput(cmdExecute)

        for node in status.keys():
            if status[node] != 0:
                failedNodes += "%s " % node
            else:
                succeedNodes += "%s " % node
        if failedNodes != "" and succeedNodes != "":
            GaussLog.printMessage("Execute command failed on %s." % failedNodes)
            GaussLog.printMessage("Execute command succeed on %s.\n" % succeedNodes)
        elif failedNodes == "":
            GaussLog.printMessage("Execute command succeed on all nodes.\n")
        elif succeedNodes == "":
            GaussLog.printMessage("Execute command failed on all nodes.\n")

        GaussLog.printMessage("Output:\n%s" % output)

        cmdFileRm = "rm %s" % cmdFile
        g_sshTool.executeCommand(cmdFileRm, "rm cmdFile")

    except Exception, e:
        if fp:
            fp.close()
        cmdFileRm = "rm %s" % cmdFile
        g_sshTool.executeCommand(cmdFileRm, "rm cmdFile")
        GaussLog.exitWithError(str(e))
Example #9
0
            usage()
            sys.exit(0)
        elif (key == "-U"):
            g_clusterUser = value
        elif (key == "-P"):
            dbInitParams.append(value)
        elif (key == "-G"):
            gtmInitParams.append(value)
        elif (key == "-l"):
            logFile = os.path.abspath(value)

    # check if user exist and is the right user
    PlatformCommand.checkUser(g_clusterUser)
        
    if (logFile == ""):
        logFile = DefaultValue.getOMLogPath(DefaultValue.DEFAULT_LOG_FILE, g_clusterUser, "")

    # Init logger
    global g_logger
    g_logger = GaussLog(logFile, "InitInstance")
    try:
        dbInit = initDbNode(dbInitParams, gtmInitParams)
        dbInit.run()
        
        g_logger.log("Init instances on node[%s] successfully!" % socket.gethostname())
        g_logger.closeLog()
        sys.exit(0)
    except Exception, e:
        g_logger.logExit(str(e))

if __name__ == '__main__':