Пример #1
0
def cmd(cmd):
    game = state.game
    language = state.language
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"],["a","1.1.1.1"]]
    state.ignoreErrorHost = True
    ccthread.run(execute,cmd)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-------------连接失败主机-----------------"
        print state.errorHost
        resultStatus = False
    if len(state.errorResult) > 0:
        resultStatus = False
        print "-------------命令执行失败服务器-----------"
        for i in state.errorResult:
            print "[%s] Error:%s"%(i,state.errorResult[i])
        print "-------------更新失败服务器汇总为---------"
        print getSpecialServerIp(state.servers,state.errorResult.keys())
    print "----------------汇总-------------------"
    print "执行服务器总数: %d"%len(state.servers)
    print "执行失败服务器数: %d" %len(state.errorResult)
    print "连接失败IP数: %d" %len(state.errorHost)
    if not resultStatus:
        sys.exit(1)
Пример #2
0
def restart(type):
    if not type:
        print "ERROR: restartType 必须指定!"
        sys.exit(1)
    game = state.game
    language = state.language
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"],["a","1.1.1.1"]]
    state.ignoreErrorHost = True
    state.threadInterval = 3
    ccthread.run(execute,type)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-------------连接失败主机-----------------"
        print state.errorHost
        resultStatus = False
    if len(state.errorResult) > 0:
        resultStatus = False
        print "-------------命令执行失败服务器-----------"
        for i in state.errorResult:
            print "[%s] Error:%s"%(i,state.errorResult[i])
        print "-------------重启失败服务器汇总为---------"
        print getSpecialServerIp(state.servers,state.errorResult.keys())
    print "----------------汇总-------------------"
    print "执行服务器总数: %d"%len(state.servers)
    print "执行失败服务器数: %d" %len(state.errorResult)
    print "连接失败IP数: %d" %len(state.errorHost)
    if not resultStatus:
        raise Exception("重启失败!")
Пример #3
0
def get(localfile,remotefile):
    game = state.game
    language = state.language
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"],["a","1.1.1.1"]]
    state.ignoreErrorHost = True
    ccthread.run(execute,remotefile,localfile)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-------------连接失败主机-----------------"
        print state.errorHost
        resultStatus = False
    if len(state.errorResult) > 0:
        resultStatus = False
        print "-------------命令执行失败服务器-----------"
        for i in state.errorResult:
            print "[%s] Error:%s"%(i,state.errorResult[i])
        print "-------------更新失败服务器汇总为---------"
        print getSpecialServerIp(state.servers,state.errorResult.keys())
    print "----------------汇总-------------------"
    print "执行服务器总数: %d"%len(state.servers)
    print "执行失败服务器数: %d" %len(state.errorResult)
    print "连接失败IP数: %d" %len(state.errorHost)
    if not resultStatus:
        sys.exit(1)
Пример #4
0
def run(options):
    global curdate,curtime,sqldir
    sqldir = options.sqldir.strip()
    state.ignoreErrorHost = True
    backstageDB = arg.gameOption("backstage_db")
    headTag = arg.gameOption("backstage_tag")
    is_mobile = arg.gameOption("is_mobile",type="bool")
    if is_mobile:
        partnersType = 2
    else:
        partnersType = 1
    backstageIp = arg.gameOption("backstage")
    #serverlistList = serverlist.serverRange(backstageDB,headTag,partnersType,"main",backstageIp,serverlist='.*')
    serverlistList = arg.getserverlist(ServerList=".*")
    #serverlistList = [["feiliu_88888",'10.6.196.30'],['feiliu_88889','10.6.196.30']]
    curdate = datetime.datetime.now().strftime("%Y%m%d")
    curtime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    ftpdir = "/app/online/%s/sql/%s/%s/"%(state.game,state.language,sqldir)
    if not os.path.isdir(ftpdir):
        print "%s不存在!"%ftpdir
        sys.exit(1)
    os.chdir(ftpdir)
    result=os.system("dos2unix md5.txt && chown virtual_user.virtual_user md5.txt && md5sum -c md5.txt")
    if result !=0:
        print "md5校验失败,请确认!"
        sys.exit(1)
    if os.path.exists( sqldir + ".zip"):
        status = os.system("unzip *.zip")
        if status != 0:
            print "解压%s.zip失败!"%sqldir
            sys.exit(1)
        else:
            if os.path.exists(sqldir):
                os.chdir(sqldir)
    newserverlist = []
    for file in os.listdir("."):
        if file.endswith(".sql"):
            servername = os.path.splitext(file)[0]
            for item in serverlistList:
                if state.game + "_" + item[0] == servername:
                    newserverlist.append(item)
                    break
            else:
                print "%s不存在该服务器列表"%servername
                state.errorResult[servername] = "不存在该服务器"
                continue
                #sys.exit(1)
    state.servers = newserverlist
    ccthread.run(executeSql)
    if len(state.errorHost) > 0:
        print "*" * 40,"连接失败ip如下:"
        print state.errorHost.keys()
    if len(state.errorResult) > 0:
        print "*"*40,"执行失败游戏服如下:"
        print arg.getSpecialServerIp(state.servers,state.errorResult.keys())
    print "执行游戏服数:",len(state.servers)
    print "执行失败数  :",len(state.errorResult)
    print "连接失败ip数:",len(state.errorHost)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        sys.exit(1)
Пример #5
0
def restart(type):
    if not type:
        print "ERROR: restartType 必须指定!"
        sys.exit(1)
    game = state.game
    language = state.language
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"],["a","1.1.1.1"]]
    state.ignoreErrorHost = True
    state.threadInterval = 3
    ccthread.run(execute, type)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-------------连接失败主机-----------------"
        print state.errorHost
        resultStatus = False
    if len(state.errorResult) > 0:
        resultStatus = False
        print "-------------命令执行失败服务器-----------"
        for i in state.errorResult:
            print "[%s] Error:%s" % (i, state.errorResult[i])
        print "-------------重启失败服务器汇总为---------"
        print getSpecialServerIp(state.servers, state.errorResult.keys())
    print "----------------汇总-------------------"
    print "执行服务器总数: %d" % len(state.servers)
    print "执行失败服务器数: %d" % len(state.errorResult)
    print "连接失败IP数: %d" % len(state.errorHost)
    if not resultStatus:
        raise Exception("重启失败!")
Пример #6
0
def addwhiteip(iplist, yx):
    if not check.checkIpList(iplist):
        raise Exception("iplist 格式不正确:%s" % iplist)
    backstageDB = gameOption("backstage_db")
    headTag = gameOption("backstage_tag")
    ismobile = gameOption("is_mobile", type='bool')
    lyWhiteIpKey = gameOption("lyWhiteIpKey")
    if ismobile:
        partnersType = 2
    else:
        partnersType = 1
    backstageIp = gameOption("backstage")
    mixservers = serverlist.serverRange(backstageDB,
                                        headTag,
                                        partnersType,
                                        "mix",
                                        backstageIp,
                                        serverlist="%s_.*" % yx)
    resultStatus = True
    if len(mixservers) == 0:
        raise Exception("没有获取到游戏列表,请确认!")
    state.servers = mixservers
    state.ignoreErrorHost = True
    ccthread.run(updateProperties, iplist, yx, lyWhiteIpKey)
    proxy_pay1_ip = gameOption("proxy_pay1_ip", default="")
    proxy_pay2_ip = gameOption("proxy_pay2_ip", default="")
    proxy_pay1 = gameOption("proxy_pay1", default="")
    proxy_pay2 = gameOption("proxy_pay2", default="")
    if proxy_pay1.strip() != "":
        proxy_pay1_ssh = ssh.ssh(proxy_pay1_ip)
        updateProxy(proxy_pay1_ssh, proxy_pay1_ip, proxy_pay1, iplist, yx,
                    lyWhiteIpKey)
    if proxy_pay2.strip() != "":
        proxy_pay2_ssh = ssh.ssh(proxy_pay2_ip)
        updateProxy(proxy_pay2_ssh, proxy_pay2_ip, proxy_pay2, iplist, yx,
                    lyWhiteIpKey)
    if len(state.errorResult) > 0:
        resultStatus = False
        print "\n", "*" * 50
        for i in state.errorResult:
            print "[%s] %s" % (i, state.errorResult[i])
    print "\n", "*" * 50
    print "更新服务器数:%d" % len(mixservers)
    print "更新失败数:%d" % len(state.errorResult)
    print "连接失败服务器数量:%d" % len(state.errorHost)
    try:
        import template
        templateObj = template.template(state.game,
                                        state.language,
                                        mixservers[0][0],
                                        ip=mixservers[0][1])
        templateObj.updateServerProperties()
        print "更新模板成功!"
    except Exception, e1:
        resultStatus = False
        print "ERROR:模板更新失败!msg:%s" % str(e1)
Пример #7
0
def hotswap(type, keyword, backendVersion=None):
    global succList, errorDict
    succList = []
    errorDict = {}
    game = state.game
    language = state.language
    www_ip = gameOption("www_ip")
    www_ssh_ip = gameOption("www_ssh_ip")
    www_port = gameOption("www_port", default="80")
    www_header = gameOption("www_header")
    www_root = gameOption("www_root")
    www_ssh = ssh.ssh(www_ssh_ip)
    www_hotswap_dir = "%s/%s/hotswap" % (www_root, game)
    www_ssh.cmd("mkdir -p " + www_hotswap_dir)
    if type != "update" and type != "remote":
        print "ERROR: 动更类型必须为update或者remote!"
        sys.exit(1)
    www_ssh.put("/app/online/%s/hotswap/%s/hotswap.zip" % (game, language),
                remote_path=www_hotswap_dir)
    ##动更包上传资源目录后删除ftp上的动更包
    os.popen("rm -f /app/online/%s/hotswap/%s/hotswap.zip" % (game, language))
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"]]
    state.ignoreErrorHost = True
    ccthread.run(execute, type, keyword, www_ip, www_port, www_header)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-" * 40 + "连接失败主机" + "-" * 30
        print state.errorHost
        resultStatus = False
    if len(errorDict) > 0:
        print "-" * 40 + "命令执行失败服务器" + "-" * 24
        for i in errorDict:
            print "[%s] Error:%s" % (i, errorDict[i])
        print "-" * 40 + "更新失败服务器汇总为" + "-" * 22
        print getSpecialServerIp(state.servers, errorDict.keys())
        resultStatus = False
    print "-" * 40 + "汇总" + "-" * 38
    print "更新服务器总数: %d" % len(state.servers)
    print "更新失败服务器数: %d" % len(errorDict)
    print "更新成功服务器数: %d" % len(succList)
    sys.stdout.flush()
    if not check.nullCheck(backendVersion):
        print "*" * 40 + "开始上传后端..."
        status, out = commands.getstatusoutput(
            "sh /app/opbin/rundeck/online.backend -t '%s' -g '%s'" %
            (backendVersion, game))
        print out
        if status != 0:
            print "ERROR: 后端%s上传失败!" % backendVersion
            resultStatus = False
    if not resultStatus:
        sys.exit(1)
Пример #8
0
def hotswap(type,keyword,backendVersion=None):
    global succList,errorDict
    succList = []
    errorDict = {}
    game = state.game
    language = state.language
    www_ip = gameOption("www_ip")
    www_ssh_ip = gameOption("www_ssh_ip")
    www_port = gameOption("www_port",default="80")
    www_header = gameOption("www_header")
    www_root = gameOption("www_root")
    www_ssh = ssh.ssh(www_ssh_ip)
    www_hotswap_dir = "%s/%s/hotswap"%(www_root,game)
    www_ssh.cmd("mkdir -p " + www_hotswap_dir)
    if type != "update" and type != "remote":
        print "ERROR: 动更类型必须为update或者remote!"
        sys.exit(1)
    www_ssh.put("/app/online/%s/hotswap/%s/hotswap.zip"%(game,language),remote_path=www_hotswap_dir)
    ##动更包上传资源目录后删除ftp上的动更包
    os.popen("rm -f /app/online/%s/hotswap/%s/hotswap.zip"%(game,language))
    serverlist = getserverlist()
    state.servers = serverlist
    #state.servers = [["feiliu_10010","10.6.197.215"]]
    state.ignoreErrorHost = True
    ccthread.run(execute,type,keyword,www_ip,www_port,www_header)
    resultStatus = True
    if len(state.errorHost) > 0:
        print "-"*40 + "连接失败主机" + "-"*30
        print state.errorHost
        resultStatus = False
    if len(errorDict) > 0:
        print "-"*40 + "命令执行失败服务器" + "-"*24
        for i in errorDict:
            print "[%s] Error:%s"%(i,errorDict[i])
        print "-"*40 + "更新失败服务器汇总为" + "-"*22
        print getSpecialServerIp(state.servers,errorDict.keys())
        resultStatus = False
    print "-"*40 + "汇总" + "-"*38
    print "更新服务器总数: %d"%len(state.servers)
    print "更新失败服务器数: %d" %len(errorDict)
    print "更新成功服务器数: %d" %len(succList)
    sys.stdout.flush()
    if not check.nullCheck(backendVersion):
        print "*" * 40 + "开始上传后端..."
        status,out = commands.getstatusoutput("sh /app/opbin/rundeck/online.backend -t '%s' -g '%s'"%(backendVersion,game))
        print out
        if status != 0:
            print "ERROR: 后端%s上传失败!"%backendVersion
            resultStatus = False
    if not resultStatus:
        sys.exit(1)
Пример #9
0
def addwhiteip(iplist,yx):
    if not check.checkIpList(iplist):
        raise Exception("iplist 格式不正确:%s"%iplist)
    backstageDB = gameOption("backstage_db")
    headTag = gameOption("backstage_tag")
    ismobile = gameOption("is_mobile",type='bool')
    lyWhiteIpKey = gameOption("lyWhiteIpKey")
    if ismobile:
        partnersType = 2
    else:
        partnersType = 1
    backstageIp = gameOption("backstage")
    mixservers = serverlist.serverRange(backstageDB,headTag,partnersType,"mix",backstageIp,serverlist="%s_.*"%yx)
    resultStatus = True
    if len(mixservers) == 0:
        raise Exception("没有获取到游戏列表,请确认!")
    state.servers = mixservers
    state.ignoreErrorHost = True
    ccthread.run(updateProperties,iplist,yx,lyWhiteIpKey)
    proxy_pay1_ip = gameOption("proxy_pay1_ip",default="")
    proxy_pay2_ip = gameOption("proxy_pay2_ip",default="")
    proxy_pay1 = gameOption("proxy_pay1",default="")
    proxy_pay2 = gameOption("proxy_pay2",default="")
    if proxy_pay1.strip() != "":
        proxy_pay1_ssh = ssh.ssh(proxy_pay1_ip)
        updateProxy(proxy_pay1_ssh,proxy_pay1_ip,proxy_pay1,iplist,yx,lyWhiteIpKey)
    if proxy_pay2.strip() != "":
        proxy_pay2_ssh = ssh.ssh(proxy_pay2_ip)
        updateProxy(proxy_pay2_ssh,proxy_pay2_ip,proxy_pay2,iplist,yx,lyWhiteIpKey)
    if len(state.errorResult) > 0:
        resultStatus = False
        print "\n","*" * 50
        for i  in state.errorResult:
            print "[%s] %s"%(i,state.errorResult[i])
    print "\n","*" * 50
    print "更新服务器数:%d"%len(mixservers)
    print "更新失败数:%d"%len(state.errorResult)
    print "连接失败服务器数量:%d"%len(state.errorHost)
    try:
        import template
        templateObj = template.template(state.game,state.language,mixservers[0][0],ip=mixservers[0][1])
        templateObj.updateServerProperties()
        print "更新模板成功!"
    except Exception,e1:
        resultStatus = False
        print "ERROR:模板更新失败!msg:%s"%str(e1)
Пример #10
0
def run(options):
    global curdate, curtime
    state.ignoreErrorHost = True
    serverlist = arg.getserverlist()
    #serverlist = [["feiliu_88888",'10.6.196.30'],['feiliu_88889','10.6.196.30']]
    state.servers = serverlist

    sqlfilepath = options.sqlfile.strip()
    sqldirpath = "/app/online/%s/sql/%s/%s" % (state.game, options.language,
                                               sqlfilepath)
    ftpdir = os.path.abspath(os.path.dirname(sqldirpath))
    sqlfile = os.path.basename(sqldirpath)
    if not ftpdir.startswith("/app/online/%s/sql/%s" %
                             (state.game, state.language)):
        print "ftp path:%s路径错误!" % ftpdir

    curdate = datetime.datetime.now().strftime("%Y%m%d")
    curtime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    if not os.path.isdir(ftpdir):
        print "%s不存在!" % ftpdir
        sys.exit(1)
    os.chdir(ftpdir)
    result = os.system(
        "dos2unix md5.txt && chown virtual_user.virtual_user md5.txt && md5sum -c md5.txt"
    )
    if result != 0:
        print "md5校验失败,请确认!"
        sys.exit(1)
    ccthread.run(executeSql, sqlfile)
    if len(state.errorHost) > 0:
        print "*" * 40, "连接失败ip如下:"
        print state.errorHost.keys()
    if len(state.errorResult) > 0:
        print "*" * 40, "执行失败游戏服如下:"
        print arg.getSpecialServerIp(state.servers, state.errorResult.keys())
    if len(state.errorHost) == 0 and len(state.errorResult) == 0:
        os.system("rm -f %s/%s" % (ftpdir, sqlfile))
    print "执行游戏服数:", len(state.servers)
    print "执行失败数  :", len(state.errorResult)
    print "连接失败ip数:", len(state.errorHost)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        sys.exit(1)
Пример #11
0
def run(options):
    global curdate,curtime
    state.ignoreErrorHost = True
    serverlist = arg.getserverlist()
    #serverlist = [["feiliu_88888",'10.6.196.30'],['feiliu_88889','10.6.196.30']]
    state.servers = serverlist

    sqlfilepath = options.sqlfile.strip()
    sqldirpath = "/app/online/%s/sql/%s/%s"%(state.game,options.language,sqlfilepath)
    ftpdir = os.path.abspath(os.path.dirname(sqldirpath))
    sqlfile = os.path.basename(sqldirpath)
    if not ftpdir.startswith("/app/online/%s/sql/%s"%(state.game,state.language)):
        print "ftp path:%s路径错误!"%ftpdir

    curdate = datetime.datetime.now().strftime("%Y%m%d")
    curtime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
    if not os.path.isdir(ftpdir):
        print "%s不存在!"%ftpdir
        sys.exit(1)
    os.chdir(ftpdir)
    result=os.system("dos2unix md5.txt && chown virtual_user.virtual_user md5.txt && md5sum -c md5.txt")
    if result !=0:
        print "md5校验失败,请确认!"
        sys.exit(1)
    ccthread.run(executeSql,sqlfile)
    if len(state.errorHost) > 0:
        print "*" * 40,"连接失败ip如下:"
        print state.errorHost.keys()
    if len(state.errorResult) > 0:
        print "*"*40,"执行失败游戏服如下:"
        print arg.getSpecialServerIp(state.servers,state.errorResult.keys())
    if len(state.errorHost) == 0 and len(state.errorResult) == 0:
        os.system("rm -f %s/%s"%(ftpdir,sqlfile))
    print "执行游戏服数:",len(state.servers)
    print "执行失败数  :",len(state.errorResult)
    print "连接失败ip数:",len(state.errorHost)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0 :
        sys.exit(1)
Пример #12
0
def update(sqlOrNot,sqlFile,backendUpload,backendChangeOrNot,backendName,executeVersionList,restart,resourceDir,replaceFile,addFile,addContent,specialScript,specialScriptExecuteFirst):
    global wwwSsh,remoteShellPath,updateScript,updateScriptPath,remoteWorkDir,remoteLogDir
    updateScriptPath = os.path.abspath(os.path.dirname(__file__))
    updateScript = "updateOnServer.py"
    remoteShellPath = mainOption("clientrootdir").replace("${game}",state.options.game).strip()
    remoteLogDir = remoteShellPath + "/logs"
    nowTimeStr = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f")
    remoteWorkDir = "update_" + nowTimeStr
    print "远端工作目录: " + remoteWorkDir
    sys.stdout.flush()
    www_header = gameOption("www_header")
    www_ip = gameOption("www_ip")
    www_port = gameOption("www_port")
    wwwSsh = ssh.ssh(www_ip)
    versionTag = gameOption("versionTag")
    specialScriptFileName = None
    if not null(specialScript):
        specialScriptFileName = os.path.basename(specialScript)
    haveFileDownload = False
    nullCheck(restart,"必须指定是否重启")
    remoteResourceDir = None
    changeBackendName = None
    needFileCheck(resourceDir,replaceFile)
    needFileCheck(resourceDir,addFile)
    needFileCheck(resourceDir,addContent)
    if sqlOrNot == "yes":
        nullCheck(sqlFile,"sql文件名称必须给出")
        resourceFileCheck(resourceDir,sqlFile)
    if backendChangeOrNot == "yes" or backendUpload == "yes":
        nullCheck(backendName,"后端名称需要给出")
    if backendChangeOrNot == "yes":
        changeBackendName = "-".join(backendName.split("-")[0:3])
    if not null(specialScript):
        if specialScriptExecuteFirst not in ["yes","no"]:
            print "ERROR: 必须指定特殊脚本执行顺序!yes:停服后即执行!no:更新完之后执行特殊脚本!现在的值为: " + specialScriptExecuteFirst
            sys.exit(1)
    if sqlOrNot == "yes" or not null(replaceFile) or not null(addFile) or not null(addContent) or not null(specialScript):
        nullCheck(resourceDir,"资源目录必须指定") 
        remoteResourceDir = resourceDir.strip() + "_" + nowTimeStr
        nullCheck(executeVersionList,"必须给出需要更新的版本")
        nullCheck(www_header,"www_header必须配置")
        nullCheck(www_ip,"www_ip必须配置")
        nullCheck(www_port,"www_port必须配置")
        www_root = gameOption("www_root")
        print "上传文件到资源服务器..."
        sys.stdout.flush()
        resourceToWww(resourceDir,www_root,specialScript,remoteResourceDir)
        print "上传文件到资源服务器完毕!"
        print "资源服务器目录为:" + remoteResourceDir
        sys.stdout.flush()
    #判断是否需要上传后端包
    if backendUpload == "yes":
        upload(backendName)
    #多线程,执行更新前的准备
    #serverlist = getserverlist()
    #serverlist = [["feiliuapp_10010","10.6.197.215"],["feiliu_99999","10.6.197.215"]]
    serverlist = [["feiliuapp_9999","10.6.197.167"]]
    distinctServer = list(set([i[1] for i in serverlist]))
    state.servers = distinctServer
    state.ignoreErrorHost = True
    ccthread.run(scriptDeploy)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        raise Exception( "更新脚本md5检查及目录检查失败,更新失败!" )
    #执行更新操作
    state.servers = serverlist
    print "--------------------------开始更新---------------------------------"
    sys.stdout.flush()
    ccthread.run(executeUpdate,sqlOrNot,sqlFile,backendChangeOrNot,changeBackendName,executeVersionList,restart,www_header,www_ip,www_port,replaceFile,addFile,addContent,specialScriptExecuteFirst,versionTag,specialScriptFileName,remoteResourceDir)
    print "更新命令发送完毕!等待更新结果 ..."
    sys.stdout.flush()
    time.sleep(160)
    #开始检查更新结果
    print "--------------------------开始检查结果----------------------------"
    sys.stdout.flush()
    ccthread.run(checkUpdateResult,restart)
    if len(state.errorHost) > 0:
        print "ERROR:错误主机:\n" + str(state.errorHost)
        sys.stdout.flush()
    else:
        print "没有错误主机!"
    if len(state.errorResult) > 0:
        print "ERROR:更新失败服务器:\n" + str(state.errorResult.keys())
        sys.stdout.flush()
    else:
        print "没有更新失败服务器!"
    print "IMPORTANT: 请生成新的模板信息!!!!!!!!!!!!"
    print "IMPORTANT: 请更新跨服gw跟match服务器!!!!!!!!!!!!"
Пример #13
0
def update(sqlFile, backendName, executeVersionList, executeDbVersionList,
           restart, resourceDir, replaceFile, addFile, addContent,
           specialScript, specialScriptExecuteFirst, frontName,
           updateTemplate):
    global wwwSsh, remoteShellPath, updateScript, updateScriptPath, remoteWorkDir, remoteLogDir, onessh, oneservername
    updateScriptPath = os.path.abspath(os.path.dirname(__file__))
    updateScript = "updateOnServer.py"
    remoteShellPath = mainOption("clientrootdir").replace(
        "${game}", state.options.game).strip()
    remoteLogDir = remoteShellPath + "/logs"
    nowTimeStr = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f")
    remoteWorkDir = "update_" + nowTimeStr
    print "远端工作目录: " + remoteWorkDir
    sys.stdout.flush()
    www_header = gameOption("www_header")
    www_ip = gameOption("www_ip")
    www_ssh_ip = gameOption("www_ssh_ip")
    www_port = gameOption("www_port", default="80")
    wwwSsh = ssh.ssh(www_ssh_ip)
    versionTag = gameOption("versionTag")
    specialScriptFileName = None
    if not null(specialScript):
        specialScriptFileName = os.path.basename(specialScript)
    haveFileDownload = False
    nullCheck(restart, "必须指定是否重启")
    remoteResourceDir = None
    changeBackendName = None
    #获取需要更新的游戏服器
    serverlist = getserverlist()
    #serverlist = [["feiliuapp_10010","10.6.197.215"],["feiliu_99999","10.6.197.215"]]
    #serverlist = [["feiliu_10001","10.6.197.215"]]
    if len(serverlist) == 0:
        raise Exception("服务器列表为空,请确认!")
    oneserver = serverlist[0]
    if isinstance(oneserver, list):
        oneip = oneserver[1]
        oneservername = oneserver[0]
    else:
        oneip = oneserver
        oneservername = oneserver
    onessh = ssh.ssh(oneip)
    needFileCheck(resourceDir, replaceFile)
    needFileCheck(resourceDir, addFile)
    needFileCheck(resourceDir, addContent)
    if not null(sqlFile):
        #resourceFileCheck(resourceDir,sqlFile)
        sqlFileCheck(resourceDir, sqlFile)
    if not null(backendName):
        changeBackendName = "-".join(backendName.split("-")[0:3]).strip()
        if not checkFrontBackendVersion(changeBackendName):
            raise Exception("ERROR: [%s] 后端版本格式不正确" % changeBackendName)
        #判断是否需要上传后端
        print "/app/online/%s/backend/%s" % (state.game, backendName.strip())
        if os.path.exists("/app/online/%s/backend/%s" %
                          (state.game, backendName.strip())):
            print "开始上传后端包..."
            sys.stdout.flush()
            status, out = commands.getstatusoutput(
                "sh /app/opbin/rundeck/online.backend -g %s -t %s" %
                (state.game, backendName.strip()))
            print out
            if status != 0:
                print "ERROR: 后端包%s上传失败!" % backendName.strip()
                sys.exit(1)
            sys.stdout.flush()
    changeFrontName = None
    if not null(frontName):
        changeFrontName = "-".join(frontName.split("-")[0:3])
        if not checkFrontBackendVersion(changeFrontName):
            raise Exception("ERROR: [%s] 前端版本格式不正确" % changeFrontName)
    if not null(specialScript):
        if specialScriptExecuteFirst not in ["yes", "no"]:
            raise Exception(
                "ERROR: 必须指定特殊脚本执行顺序!yes:停服后即执行!no:更新完之后执行特殊脚本!现在的值为: " +
                specialScriptExecuteFirst)
    if not null(sqlFile) or not null(replaceFile) or not null(
            addFile) or not null(addContent):
        nullCheck(resourceDir, "资源目录必须指定")
    if not null(sqlFile) or not null(replaceFile) or not null(
            addFile) or not null(addContent) or not null(specialScript):
        remoteResourceDir = resourceDir.strip() + "_" + nowTimeStr
        #nullCheck(executeVersionList,"必须给出需要更新的版本")
        if null(executeVersionList) and null(executeDbVersionList):
            print "必须给出需要更新的版本或者数据库版本"
            sys.exit(1)
        nullCheck(www_header, "www_header必须配置")
        nullCheck(www_ip, "www_ip必须配置")
        nullCheck(www_port, "www_port必须配置")
        www_root = gameOption("www_root")
        print "上传文件到资源服务器..."
        sys.stdout.flush()
        resourceToWww(resourceDir, www_root, specialScript, remoteResourceDir)
        print "上传文件到资源服务器完毕!"
        print "资源服务器目录为:" + remoteResourceDir
        sys.stdout.flush()
    #判断是否需要上传后端包
    #if backendUpload == "yes":
    #    upload(backendName)
    #多线程,执行更新前的准备
    distinctServer = list(set([i[1] for i in serverlist]))
    state.servers = distinctServer
    state.ignoreErrorHost = True
    ccthread.run(scriptDeploy)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        raise Exception("更新脚本md5检查及目录检查失败,更新失败!")
    #执行更新操作
    state.servers = serverlist
    print "--------------------------开始更新---------------------------------"
    sys.stdout.flush()
    state.threadInterval = 4
    ccthread.run(executeUpdate, sqlFile, changeBackendName, executeVersionList,
                 executeDbVersionList, restart, www_header, www_ip, www_port,
                 replaceFile, addFile, addContent, specialScriptExecuteFirst,
                 versionTag, specialScriptFileName, remoteResourceDir,
                 changeFrontName)
    print "更新命令发送完毕!等待更新结果 ..."
    sys.stdout.flush()
    time.sleep(300)
    #开始检查更新结果
    print "--------------------------开始检查结果----------------------------"
    sys.stdout.flush()
    state.threadInterval = None
    ccthread.run(checkUpdateResult, restart)
    updateSucc = True
    if len(state.errorHost) > 0:
        updateSucc = False
        print "*" * 50 + "ERROR:错误主机:"
        for i in state.errorHost:
            print i
        sys.stdout.flush()
    else:
        print "没有错误主机!"
    if len(state.errorResult) > 0:
        updateSucc = False
        print "*" * 50 + "ERROR:更新失败服务器:"
        for i in state.errorResult.keys():
            print "[%s]%s" % (i, state.errorResult[i])
        sys.stdout.flush()
        print "*" * 50 + "更新失败服务器列表:"
        print getSpecialServerIp(state.servers, state.errorResult.keys())
        sys.stdout.flush()
    else:
        print "没有更新失败服务器!"
    print "----------------汇总-------------------"
    print "执行服务器总数: %d" % len(state.servers)
    print "执行失败服务器数: %d" % len(state.errorResult)
    print "连接失败IP数: %d" % len(state.errorHost)

    if updateTemplate != 'null':
        print('开始更新布服模板...')
        sys.stdout.flush()
        os.system("python %s/main.py template -g %s -l %s -t %s" %
                  (os.path.abspath(os.path.dir(__file__)), state.game,
                   state.language, updateTemplate))
    else:
        print "IMPORTANT: 请自行确定是否生成新的模板信息!!!!!!!!!!!!"
        print "IMPORTANT: 请自行确定是否需要更新跨服gw跟match服务器!!!!!!!!!!!!"

    if not updateSucc:
        sys.exit(1)
Пример #14
0
def update(sqlOrNot, sqlFile, backendUpload, backendChangeOrNot, backendName,
           executeVersionList, restart, resourceDir, replaceFile, addFile,
           addContent, specialScript, specialScriptExecuteFirst):
    global wwwSsh, remoteShellPath, updateScript, updateScriptPath, remoteWorkDir, remoteLogDir
    updateScriptPath = os.path.abspath(os.path.dirname(__file__))
    updateScript = "updateOnServer.py"
    remoteShellPath = mainOption("clientrootdir").replace(
        "${game}", state.options.game).strip()
    remoteLogDir = remoteShellPath + "/logs"
    nowTimeStr = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f")
    remoteWorkDir = "update_" + nowTimeStr
    print "远端工作目录: " + remoteWorkDir
    sys.stdout.flush()
    www_header = gameOption("www_header")
    www_ip = gameOption("www_ip")
    www_port = gameOption("www_port")
    wwwSsh = ssh.ssh(www_ip)
    versionTag = gameOption("versionTag")
    specialScriptFileName = None
    if not null(specialScript):
        specialScriptFileName = os.path.basename(specialScript)
    haveFileDownload = False
    nullCheck(restart, "必须指定是否重启")
    remoteResourceDir = None
    changeBackendName = None
    needFileCheck(resourceDir, replaceFile)
    needFileCheck(resourceDir, addFile)
    needFileCheck(resourceDir, addContent)
    if sqlOrNot == "yes":
        nullCheck(sqlFile, "sql文件名称必须给出")
        resourceFileCheck(resourceDir, sqlFile)
    if backendChangeOrNot == "yes" or backendUpload == "yes":
        nullCheck(backendName, "后端名称需要给出")
    if backendChangeOrNot == "yes":
        changeBackendName = "-".join(backendName.split("-")[0:3])
    if not null(specialScript):
        if specialScriptExecuteFirst not in ["yes", "no"]:
            print "ERROR: 必须指定特殊脚本执行顺序!yes:停服后即执行!no:更新完之后执行特殊脚本!现在的值为: " + specialScriptExecuteFirst
            sys.exit(1)
    if sqlOrNot == "yes" or not null(replaceFile) or not null(
            addFile) or not null(addContent) or not null(specialScript):
        nullCheck(resourceDir, "资源目录必须指定")
        remoteResourceDir = resourceDir.strip() + "_" + nowTimeStr
        nullCheck(executeVersionList, "必须给出需要更新的版本")
        nullCheck(www_header, "www_header必须配置")
        nullCheck(www_ip, "www_ip必须配置")
        nullCheck(www_port, "www_port必须配置")
        www_root = gameOption("www_root")
        print "上传文件到资源服务器..."
        sys.stdout.flush()
        resourceToWww(resourceDir, www_root, specialScript, remoteResourceDir)
        print "上传文件到资源服务器完毕!"
        print "资源服务器目录为:" + remoteResourceDir
        sys.stdout.flush()
    #判断是否需要上传后端包
    if backendUpload == "yes":
        upload(backendName)
    #多线程,执行更新前的准备
    #serverlist = getserverlist()
    #serverlist = [["feiliuapp_10010","10.6.197.215"],["feiliu_99999","10.6.197.215"]]
    serverlist = [["feiliuapp_9999", "10.6.197.167"]]
    distinctServer = list(set([i[1] for i in serverlist]))
    state.servers = distinctServer
    state.ignoreErrorHost = True
    ccthread.run(scriptDeploy)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        raise Exception("更新脚本md5检查及目录检查失败,更新失败!")
    #执行更新操作
    state.servers = serverlist
    print "--------------------------开始更新---------------------------------"
    sys.stdout.flush()
    ccthread.run(executeUpdate, sqlOrNot, sqlFile, backendChangeOrNot,
                 changeBackendName, executeVersionList, restart, www_header,
                 www_ip, www_port, replaceFile, addFile, addContent,
                 specialScriptExecuteFirst, versionTag, specialScriptFileName,
                 remoteResourceDir)
    print "更新命令发送完毕!等待更新结果 ..."
    sys.stdout.flush()
    time.sleep(160)
    #开始检查更新结果
    print "--------------------------开始检查结果----------------------------"
    sys.stdout.flush()
    ccthread.run(checkUpdateResult, restart)
    if len(state.errorHost) > 0:
        print "ERROR:错误主机:\n" + str(state.errorHost)
        sys.stdout.flush()
    else:
        print "没有错误主机!"
    if len(state.errorResult) > 0:
        print "ERROR:更新失败服务器:\n" + str(state.errorResult.keys())
        sys.stdout.flush()
    else:
        print "没有更新失败服务器!"
    print "IMPORTANT: 请生成新的模板信息!!!!!!!!!!!!"
    print "IMPORTANT: 请更新跨服gw跟match服务器!!!!!!!!!!!!"
Пример #15
0
def update(sqlFile,backendName,executeVersionList,executeDbVersionList,restart,resourceDir,replaceFile,addFile,addContent,specialScript,specialScriptExecuteFirst,frontName,updateTemplate):
    global wwwSsh,remoteShellPath,updateScript,updateScriptPath,remoteWorkDir,remoteLogDir,onessh,oneservername
    updateScriptPath = os.path.abspath(os.path.dirname(__file__))
    updateScript = "updateOnServer.py"
    remoteShellPath = mainOption("clientrootdir").replace("${game}",state.options.game).strip()
    remoteLogDir = remoteShellPath + "/logs"
    nowTimeStr = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f")
    remoteWorkDir = "update_" + nowTimeStr
    print "远端工作目录: " + remoteWorkDir
    sys.stdout.flush()
    www_header = gameOption("www_header")
    www_ip = gameOption("www_ip")
    www_ssh_ip = gameOption("www_ssh_ip")
    www_port = gameOption("www_port",default="80")
    wwwSsh = ssh.ssh(www_ssh_ip)
    versionTag = gameOption("versionTag")
    specialScriptFileName = None
    if not null(specialScript):
        specialScriptFileName = os.path.basename(specialScript)
    haveFileDownload = False
    nullCheck(restart,"必须指定是否重启")
    remoteResourceDir = None
    changeBackendName = None
    #获取需要更新的游戏服器
    serverlist = getserverlist()
    #serverlist = [["feiliuapp_10010","10.6.197.215"],["feiliu_99999","10.6.197.215"]]
    #serverlist = [["feiliu_10001","10.6.197.215"]]
    if len(serverlist) == 0:
        raise Exception("服务器列表为空,请确认!")
    oneserver = serverlist[0]
    if isinstance(oneserver,list):
        oneip = oneserver[1]
        oneservername = oneserver[0]
    else:
        oneip = oneserver
        oneservername = oneserver
    onessh = ssh.ssh(oneip)
    needFileCheck(resourceDir,replaceFile)
    needFileCheck(resourceDir,addFile)
    needFileCheck(resourceDir,addContent)
    if not null(sqlFile):
        #resourceFileCheck(resourceDir,sqlFile)
        sqlFileCheck(resourceDir,sqlFile)
    if not null(backendName):
        changeBackendName = "-".join(backendName.split("-")[0:3]).strip()
        if not checkFrontBackendVersion(changeBackendName):
            raise Exception("ERROR: [%s] 后端版本格式不正确"%changeBackendName)
        #判断是否需要上传后端
        print "/app/online/%s/backend/%s"%(state.game,backendName.strip())
        if os.path.exists("/app/online/%s/backend/%s"%(state.game,backendName.strip())):
            print "开始上传后端包..."
            sys.stdout.flush()
            status,out = commands.getstatusoutput("sh /app/opbin/rundeck/online.backend -g %s -t %s"%(state.game,backendName.strip()))
            print out
            if status != 0:
                print "ERROR: 后端包%s上传失败!"%backendName.strip()
                sys.exit(1)
            sys.stdout.flush()
    changeFrontName = None
    if not null(frontName):
        changeFrontName = "-".join(frontName.split("-")[0:3])
        if not checkFrontBackendVersion(changeFrontName):
            raise Exception("ERROR: [%s] 前端版本格式不正确"%changeFrontName)
    if not null(specialScript):
        if specialScriptExecuteFirst not in ["yes","no"]:
            raise Exception("ERROR: 必须指定特殊脚本执行顺序!yes:停服后即执行!no:更新完之后执行特殊脚本!现在的值为: " + specialScriptExecuteFirst)
    if not null(sqlFile) or not null(replaceFile) or not null(addFile) or not null(addContent):
        nullCheck(resourceDir,"资源目录必须指定") 
    if not null(sqlFile) or not null(replaceFile) or not null(addFile) or not null(addContent) or not null(specialScript):
        remoteResourceDir = resourceDir.strip() + "_" + nowTimeStr
        #nullCheck(executeVersionList,"必须给出需要更新的版本")
        if null(executeVersionList) and null(executeDbVersionList):
            print "必须给出需要更新的版本或者数据库版本"
            sys.exit(1)
        nullCheck(www_header,"www_header必须配置")
        nullCheck(www_ip,"www_ip必须配置")
        nullCheck(www_port,"www_port必须配置")
        www_root = gameOption("www_root")
        print "上传文件到资源服务器..."
        sys.stdout.flush()
        resourceToWww(resourceDir,www_root,specialScript,remoteResourceDir)
        print "上传文件到资源服务器完毕!"
        print "资源服务器目录为:" + remoteResourceDir
        sys.stdout.flush()
    #判断是否需要上传后端包
    #if backendUpload == "yes":
    #    upload(backendName)
    #多线程,执行更新前的准备
    distinctServer = list(set([i[1] for i in serverlist]))
    state.servers = distinctServer
    state.ignoreErrorHost = True
    ccthread.run(scriptDeploy)
    if len(state.errorResult) > 0 or len(state.errorHost) > 0:
        raise Exception( "更新脚本md5检查及目录检查失败,更新失败!" )
    #执行更新操作
    state.servers = serverlist
    print "--------------------------开始更新---------------------------------"
    sys.stdout.flush()
    state.threadInterval = 4
    ccthread.run(executeUpdate,sqlFile,changeBackendName,executeVersionList,executeDbVersionList,restart,www_header,www_ip,www_port,replaceFile,addFile,addContent,specialScriptExecuteFirst,versionTag,specialScriptFileName,remoteResourceDir,changeFrontName)
    print "更新命令发送完毕!等待更新结果 ..."
    sys.stdout.flush()
    time.sleep(300)
    #开始检查更新结果
    print "--------------------------开始检查结果----------------------------"
    sys.stdout.flush()
    state.threadInterval = None
    ccthread.run(checkUpdateResult,restart)
    updateSucc = True
    if len(state.errorHost) > 0:
        updateSucc = False
        print "*" * 50 + "ERROR:错误主机:"
        for i in state.errorHost:
            print i
        sys.stdout.flush()
    else:
        print "没有错误主机!"
    if len(state.errorResult) > 0:
        updateSucc = False
        print "*" * 50 + "ERROR:更新失败服务器:" 
        for i in state.errorResult.keys():
            print "[%s]%s"%(i,state.errorResult[i])
        sys.stdout.flush()
        print "*"*50 + "更新失败服务器列表:"
        print getSpecialServerIp(state.servers,state.errorResult.keys())
        sys.stdout.flush()
    else:
        print "没有更新失败服务器!"
    print "----------------汇总-------------------"
    print "执行服务器总数: %d"%len(state.servers)
    print "执行失败服务器数: %d" %len(state.errorResult)
    print "连接失败IP数: %d" %len(state.errorHost)
    
    if updateTemplate != 'null':
        print('开始更新布服模板...')
        sys.stdout.flush()
        os.system("python %s/main.py template -g %s -l %s -t %s"%(os.path.abspath(os.path.dir(__file__)),state.game,state.language,updateTemplate))
    else:
        print "IMPORTANT: 请自行确定是否生成新的模板信息!!!!!!!!!!!!"
        print "IMPORTANT: 请自行确定是否需要更新跨服gw跟match服务器!!!!!!!!!!!!"

    if not updateSucc:
        sys.exit(1)