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()
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()
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'])
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'])
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))
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))
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
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)
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
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)
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()
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()
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()
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()
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()
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()
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
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
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
def reloadServer(): "平滑重启服务器" baseObj = json.loads(getConfig("config")) os.system(baseObj['nginx']['serviceReload'])
def getBaseConfig(): "获取基础数据" data=getConfig("config") return json.loads(data)
def getBaseConfig(): "获取基础数据" data = getConfig("config") return json.loads(data)
def reloadServer(): "平滑重启服务器" baseObj=json.loads(getConfig("config")) os.system(baseObj['nginx']['serviceReload'])