示例#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
示例#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)
示例#3
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))