Ejemplo n.º 1
0
def startApp(aid):
    "启动app"

    #提取应用数据
    sql = "select * from paas_app where id = %d limit 1" % (aid)
    dao = db.execute(sql)
    appData = objToDict(dao.first())
    dao.close()

    baseObj = json.loads(getConfig("config"))

    data = getConfig("mainServer")
    data = data.replace("{{ appHost }}", appData['host']).replace(
        "{{ remoteSocket }}",
        appData['remoteSocket']).replace("{{ appId }}", str(aid))

    #main_作为前缀
    fp = open(baseObj['nginx']['confPath'] + "/main_" + str(aid) + ".conf",
              "w")
    fp.write(data)
    fp.close()

    #修改状态
    sql = "update paas_app set status = 1 where id =%d" % (aid)
    dao = db.execute(sql)
    dao.close()
    #平滑重启服务器
    reloadServer()
Ejemplo n.º 2
0
def startApp(aid):
    "启动app"
    
    #提取应用数据
    sql="select * from paas_app where id = %d limit 1"%(aid)
    dao=db.execute(sql)
    appData=objToDict(dao.first())
    dao.close()
    
    baseObj=json.loads(getConfig("config"))
    
    data=getConfig("mainServer")
    data=data.replace("{{ appHost }}",appData['host']).replace("{{ remoteSocket }}",appData['remoteSocket']).replace("{{ appId }}",str(aid)) 
    
    #main_作为前缀
    fp=open(baseObj['nginx']['confPath']+"/main_"+str(aid)+".conf","w")
    fp.write(data)
    fp.close()
    
    #修改状态
    sql="update paas_app set status = 1 where id =%d"%(aid)
    dao=db.execute(sql)
    dao.close()
    #平滑重启服务器
    reloadServer()
Ejemplo n.º 3
0
def buildMainServerConfig(aid,appHost,remoteSocket):
    "生成反响代理服务器配置文件"
    data=getConfig("mainServer")
    data=data.replace("{{ appHost }}",appHost).replace("{{ remoteSocket }}",remoteSocket).replace("{{ appId }}",str(aid))
    
    baseObj=json.loads(getConfig("config"))
    #main_作为前缀
    fp=open(baseObj['nginx']['confPath']+"/main_"+str(aid)+".conf","w")
    fp.write(data)
    fp.close()
    
    #平滑加载配置文件
    os.system(baseObj['nginx']['serviceReload'])
Ejemplo n.º 4
0
def buildMainServerConfig(aid, appHost, remoteSocket):
    "生成反响代理服务器配置文件"
    data = getConfig("mainServer")
    data = data.replace("{{ appHost }}", appHost).replace(
        "{{ remoteSocket }}", remoteSocket).replace("{{ appId }}", str(aid))

    baseObj = json.loads(getConfig("config"))
    #main_作为前缀
    fp = open(baseObj['nginx']['confPath'] + "/main_" + str(aid) + ".conf",
              "w")
    fp.write(data)
    fp.close()

    #平滑加载配置文件
    os.system(baseObj['nginx']['serviceReload'])
Ejemplo n.º 5
0
def getCodeFromLocation(aid):
    "从本地代码仓库拉取代码"
    baseObj=json.loads(app.getConfig("config"))
    codePath=baseObj['base']['codePath']+"/"+str(aid)
    appPath=baseObj['base']['allAppDocument']
    os.system("rm -Rvf %s"%(appPath+"/"+str(aid)))
    os.system("cp -Rfv %s %s"%(codePath,appPath))
Ejemplo n.º 6
0
Archivo: git.py Proyecto: yubang/paas
def getCodeFromLocation(aid):
    "从本地代码仓库拉取代码"
    baseObj = json.loads(app.getConfig("config"))
    codePath = baseObj['base']['codePath'] + "/" + str(aid)
    appPath = baseObj['base']['allAppDocument']
    os.system("rm -Rvf %s" % (appPath + "/" + str(aid)))
    os.system("cp -Rfv %s %s" % (codePath, appPath))
Ejemplo n.º 7
0
Archivo: git.py Proyecto: yubang/paas
def checkLocationCode(aid):
    "检测本地是否有克隆好的代码"
    baseObj = json.loads(app.getConfig("config"))
    codePath = baseObj['base']['codePath'] + "/" + str(aid)
    if os.path.exists(codePath):
        return True
    else:
        return False
Ejemplo n.º 8
0
def pullCode(aid):
    "更新代码仓库的代码"
    baseObj=json.loads(app.getConfig("config"))
    codePath=baseObj['base']['codePath']+"/"+str(aid)
    appPath=baseObj['base']['allAppDocument']
    os.system("cd %s"%(codePath))
    os.system("git pull")
    getCodeFromLocation(aid)
Ejemplo n.º 9
0
def checkLocationCode(aid):
    "检测本地是否有克隆好的代码"
    baseObj=json.loads(app.getConfig("config"))
    codePath=baseObj['base']['codePath']+"/"+str(aid)
    if os.path.exists(codePath):
        return True
    else:
        return False
Ejemplo n.º 10
0
Archivo: git.py Proyecto: yubang/paas
def pullCode(aid):
    "更新代码仓库的代码"
    baseObj = json.loads(app.getConfig("config"))
    codePath = baseObj['base']['codePath'] + "/" + str(aid)
    appPath = baseObj['base']['allAppDocument']
    os.system("cd %s" % (codePath))
    os.system("git pull")
    getCodeFromLocation(aid)
Ejemplo n.º 11
0
def stopApp(aid):
    "停止app"
    baseObj = json.loads(getConfig("config"))
    path = baseObj['nginx']['confPath'] + "/main_" + str(aid) + ".conf"
    if os.path.exists(path):
        os.remove(path)

    #修改状态
    sql = "update paas_app set status = 3 where id =%d" % (aid)
    dao = db.execute(sql)
    dao.close()
    #平滑重启服务器
    reloadServer()
Ejemplo n.º 12
0
def stopApp(aid):
    "停止app"
    baseObj=json.loads(getConfig("config"))
    path=baseObj['nginx']['confPath']+"/main_"+str(aid)+".conf"
    if os.path.exists(path):
        os.remove(path)
        
    #修改状态
    sql="update paas_app set status = 3 where id =%d"%(aid)
    dao=db.execute(sql)
    dao.close()
    #平滑重启服务器
    reloadServer()
Ejemplo n.º 13
0
def buildNginxPhpConfig(aid,appHost,appDocument,appSocketPath,appPort):
    "动态生成nginx映射虚拟主机配置文件"
    data=getConfig("nginxPhp")
    baseObj=getBaseConfig()
    
    data=data.replace("{{ appId }}",aid)
    data=data.replace("{{ appHost }}",appHost)
    data=data.replace("{{ appDocument }}",appDocument)
    data=data.replace("{{ appSocketPath }}",appSocketPath)
    data=data.replace("{{ appPort }}",str(appPort))
    
    fp=open(baseObj['nginx']['confPath']+"/"+aid+".conf","w")
    fp.write(data)
    fp.close()
Ejemplo n.º 14
0
def buildPhpFpmConfig(aid,appSocketPath):
    "动态生成php应用虚拟主机配置文件"
    
    data=getConfig("php-fpm")
    baseObj=getBaseConfig()
    
    data=data.replace("{{ appId }}",aid)
    data=data.replace("{{ appSocketPath }}",appSocketPath)
    data=data.replace("{{ appPrefix }}",baseObj['base']['phpAppPrefix'])
    data=data.replace("{{ webGroup }}",baseObj['base']['webGroup'])
    
    fp=open(baseObj['php-fpm']['confPath']+"/"+aid+".conf","w")
    fp.write(data)
    fp.close()
Ejemplo n.º 15
0
def buildNginxPhpConfig(aid, appHost, appDocument, appSocketPath, appPort):
    "动态生成nginx映射虚拟主机配置文件"
    data = getConfig("nginxPhp")
    baseObj = getBaseConfig()

    data = data.replace("{{ appId }}", aid)
    data = data.replace("{{ appHost }}", appHost)
    data = data.replace("{{ appDocument }}", appDocument)
    data = data.replace("{{ appSocketPath }}", appSocketPath)
    data = data.replace("{{ appPort }}", str(appPort))

    fp = open(baseObj['nginx']['confPath'] + "/" + aid + ".conf", "w")
    fp.write(data)
    fp.close()
Ejemplo n.º 16
0
def buildPhpFpmConfig(aid, appSocketPath):
    "动态生成php应用虚拟主机配置文件"

    data = getConfig("php-fpm")
    baseObj = getBaseConfig()

    data = data.replace("{{ appId }}", aid)
    data = data.replace("{{ appSocketPath }}", appSocketPath)
    data = data.replace("{{ appPrefix }}", baseObj['base']['phpAppPrefix'])
    data = data.replace("{{ webGroup }}", baseObj['base']['webGroup'])

    fp = open(baseObj['php-fpm']['confPath'] + "/" + aid + ".conf", "w")
    fp.write(data)
    fp.close()
Ejemplo n.º 17
0
Archivo: git.py Proyecto: yubang/paas
def getCodeFromOsc(aid, gitUrl):
    "从osc上拉取代码"
    baseObj = json.loads(app.getConfig("config"))
    codePath = baseObj['base']['codePath'] + "/" + str(aid)
    appPath = baseObj['base']['allAppDocument']

    if not os.path.exists(codePath):
        os.makedirs(codePath)

    os.system("rm -Rvf %s" % (codePath))

    os.system("git clone %s %s" % (gitUrl, codePath))

    if not os.path.exists(codePath):
        return False

    #迁移clone下来的代码
    getCodeFromLocation(aid)

    return True
Ejemplo n.º 18
0
Archivo: git.py Proyecto: vipsql/paas
def getCodeFromOsc(aid,gitUrl):
    "从osc上拉取代码"
    baseObj=json.loads(app.getConfig("config"))
    codePath=baseObj['base']['codePath']+"/"+str(aid)
    appPath=baseObj['base']['allAppDocument']
    
    if not os.path.exists(codePath):
        os.makedirs(codePath)
    
    os.system("rm -Rvf %s"%(codePath))
        
    os.system("git clone %s %s"%(gitUrl,codePath))
    
    if not os.path.exists(codePath):
        return False
    
    #迁移clone下来的代码
    getCodeFromLocation(aid)
    
    return True
Ejemplo n.º 19
0
def getCodeFromOsc(aid,gitUrl):
    "从osc上拉取代码"
    baseObj=json.loads(app.getConfig("config"))
    codePath=baseObj['base']['codePath']+"/"+str(aid)
    appPath=baseObj['base']['allAppDocument']
    
    if not os.path.exists(codePath):
        os.makedirs(codePath)
    
    os.system("rm -Rvf %s"%(codePath))
        
    out=os.popen("git clone %s %s"%(gitUrl,codePath))
    log=out.read()
    if log.find("Receiving objects: 100%") == -1:
        return False
    
    #迁移clone下来的代码
    getCodeFromLocation(aid)
    
    return True
Ejemplo n.º 20
0
def reloadServer():
    "平滑重启服务器"
    baseObj = json.loads(getConfig("config"))
    os.system(baseObj['nginx']['serviceReload'])
Ejemplo n.º 21
0
def getBaseConfig():
    "获取基础数据"
    data=getConfig("config")
    return json.loads(data)
Ejemplo n.º 22
0
def getBaseConfig():
    "获取基础数据"
    data = getConfig("config")
    return json.loads(data)
Ejemplo n.º 23
0
def reloadServer():
    "平滑重启服务器"
    baseObj=json.loads(getConfig("config"))
    os.system(baseObj['nginx']['serviceReload'])