diff --git a/app/config.py b/app/config.py index c94e012..d199c54 100644 --- a/app/config.py +++ b/app/config.py @@ -21,13 +21,7 @@ # 远程发布目录 -host_path = '/app/web/' -go_host_path = '/app/golang/' -jobs_host_path = '/app/jobs/' - - -# 多端口项目 项目类型 -manyPort = ['python', 'nodejs'] +remote_host_path = '/app/project/' # 使用supervisord管理的进程 项目类型 supervisord_list = ['sh', 'go', 'golang', 'python', 'nodejs', 'java-jar'] @@ -36,7 +30,7 @@ # files = supervisor_conf_dir/*.conf supervisor_conf_dir = '/app/supervisor/conf/conf.d/' # 远程主机supervisor存放日志目录, 没有服务无法启动 -supervisor_log_path = '/data/log/supervisor/' +supervisor_log_path = '/data/logs/supervisor/' # 管理员菜单列表 diff --git a/app/main/deploy.py b/app/main/deploy.py index e9a3acd..8a720d4 100644 --- a/app/main/deploy.py +++ b/app/main/deploy.py @@ -47,12 +47,14 @@ def config_info(project): def gethostname(project): print(project) - sql = "SELECT `ip`,`hostname` FROM `serverinfo` WHERE project_name = '%s';" % (project) + sql = "SELECT `ip`,`hostname`,`pnum` FROM `serverinfo` WHERE project_name = '%s';" % (project) c.execute(sql) ones = c.fetchall() hostnameinfo = {} for i in ones: - hostnameinfo[i[0]] = i[1] + print(i) + hostnameinfo[i[0]] = [i[1], int(i[2])] + print(hostnameinfo) return hostnameinfo def getworkorder(project): @@ -71,17 +73,17 @@ def getworkorder(project): class Deploy: def __init__(self, project, tag, taskid, hostlist, operation, currentuser, reason): - self.project = project - self.tag = tag - self.taskid = taskid - self.hostlist = hostlist - self.operation = operation + self.project = project + self.tag = tag + self.taskid = taskid + self.hostlist = hostlist + self.operation = operation self.currentuser = currentuser - self.reason = reason + self.reason = reason - pinfo = project_info(project) - cinfo = config_info(project) - self.hostnameinfo = gethostname(project) + pinfo = project_info(project) + cinfo = config_info(project) + self.hostnameinfo = gethostname(project) self.workorderinfo = getworkorder(project) print(pinfo) @@ -89,49 +91,43 @@ def __init__(self, project, tag, taskid, hostlist, operation, currentuser, reaso print(self.hostnameinfo) print(self.workorderinfo) - self.p = pinfo[1] + self.business = pinfo[1] self.environment = pinfo[2] - self.branch = pinfo[3] - self.Type = pinfo[4] - self.git = pinfo[5] - self.port = int(pinfo[6]) - self.make = pinfo[7] - self.istag = pinfo[8] - self.isnginx = pinfo[9] - self.business = pinfo[10] - self.ischeck = pinfo[11] - self.checkurl = pinfo[12] - self.statuscode = pinfo[13] - - - self.config1 = cinfo[1] - self.config2 = cinfo[2] - self.config3 = cinfo[3] - self.config4 = cinfo[4] - self.config5 = cinfo[5] - - - self.host = 'Deploy' - self.status = 'ok' + self.p = pinfo[3] + self.Type = pinfo[4] + self.port = int(pinfo[5]) + self.git = pinfo[6] + self.branch = pinfo[7] + + + self.make = cinfo[1] + self.supervisor = cinfo[2] + self.config = cinfo[3] + self.remarks = cinfo[4] + self.startcmd = cinfo[5] + self.packfile = cinfo[6] + self.istag = cinfo[7] + self.checkport = cinfo[8] + self.checkhttp = cinfo[9] + self.httpurl = cinfo[10] + self.httpcode = cinfo[11] + + + self.host = 'Deploy' + self.status = 'ok' self.commitid = '' - self.exec_user = exec_user - self.project_path = project_path - self.basicGlist = basicGlist - self.manyPort = manyPort - self.businessRobot = businessRobot - self.sreRobot = sreRobot - self.autotestURL = autotestURL - self.autolist = autolist + self.exec_user = exec_user + self.project_path = project_path + self.basicGlist = basicGlist + self.businessRobot = businessRobot + self.sreRobot = sreRobot + self.autotestURL = autotestURL + self.autolist = autolist + self.host_path = remote_host_path print(self.autolist) - if self.Type == 'go' or self.Type == 'golang': - self.host_path = go_host_path - elif self.Type == 'jobs': - self.host_path = jobs_host_path - else: - self.host_path = host_path self.pkl_file = '%s/deploy.%s.lock' %(lock_path, project) self.loginfo = 'user: %s\nhostlist: %s\noperation: %s\nproject: %s\ntag: %s\ntaskid: %s\n' %( @@ -199,22 +195,20 @@ def hostOperation(self): self.wlogsql() def serviceStop(self): - if self.Type in self.manyPort: - portlist = self.getport() - else: - portlist = [self.port] - - for port in portlist: + print(self.hostnameinfo) + pnum = self.hostnameinfo[self.host][1] + for port in range(self.port, self.port + pnum): self.removeService(port) self.stop[self.Type](port) def serviceRestart(self): - if self.Type in self.manyPort: - portlist = self.getport() - else: - portlist = [self.port] + pnum = self.hostnameinfo[self.host][1] + print(pnum) + print(type(pnum)) + print(type(self.port)) + print(self.port + pnum) - for port in portlist: + for port in range(self.port, self.port + pnum): self.removeService(port) self.restart[self.Type](port) self.check_status(port) @@ -229,11 +223,8 @@ def serviceUpdate(self): def serviceFastback(self): self.rsyncCode[self.Type]() - if self.Type in self.manyPort: - portlist = self.getport() - else: - portlist = [self.port] - for port in portlist: + pnum = self.hostnameinfo[self.host][1] + for port in range(self.port, self.port + pnum): self.restart[self.Type](port) @@ -245,7 +236,7 @@ def addlog(self, newlog): def wlogsql(self): try: - host_name = self.hostnameinfo[self.host] + host_name = self.hostnameinfo[self.host][0] except: host_name = self.host @@ -265,7 +256,7 @@ def wlogsql(self): def updateHostCommit(self): if self.commitid: - sql = "update `serverinfo` set `variable3`='%s',`variable4`='%s' \ + sql = "update `serverinfo` set `commitid`='%s',`updatetime`='%s' \ where project_name='%s' and ip='%s'; " % ( self.commitid, self.tag, self.project, self.host) print(sql) @@ -276,9 +267,9 @@ def updateHostCommit(self): self.done() def updateTaskStatus(self): - sql = "update `updateoperation` set `loginfo`='%s',`tag`='%s' \ + sql = "update `updateoperation` set `status`='%s',`tag`='%s',`commitid`='%s' \ where project_name='%s' and taskid='%s'; " % ( - self.status, self.tag, self.project, self.taskid) + self.status, self.tag, self.commitid, self.project, self.taskid) print(sql) try: c.execute(sql) @@ -293,7 +284,7 @@ def notice(self): HL = 'hostlist:' for HOST in self.hostlist.split(','): try: - host_name = self.hostnameinfo[HOST] + host_name = self.hostnameinfo[HOST][0] except: host_name = HOST HL = HL + ' ' + host_name @@ -348,29 +339,19 @@ def expansion_notice(self): self.addlog(str(err)) - def getlasttag(self): - sql = "SELECT `tag`,`loginfo` FROM `updateoperation` \ - WHERE project_name = '%s' and operation = 'serviceUpdate' and tag != '%s' \ - order by taskid desc limit 1;" % (self.project, self.tag) - c.execute(sql) - ones = c.fetchall() - if ones: - if ones[0][1] == 'ok': - self.tag = ones[0][0] - return True - return False - - - def getlastoktag(self): - sql = "SELECT `tag` FROM `updateoperation` \ - WHERE project_name = '%s' and operation = 'serviceUpdate' and loginfo = 'ok' \ + def getlastokstatus(self): + sql = "SELECT `tag`,`commitid` FROM `updateoperation` \ + WHERE project_name = '%s' and operation = 'serviceUpdate' and status = 'ok' \ order by taskid desc limit 1;" % (self.project) c.execute(sql) ones = c.fetchall() - if not ones: - self.faildone('getlastoktag. not update ok. ') - - self.tag = ones[0][0] + if ones: + tag = ones[0][0] + commitid = ones[0][1] + else: + tag = '' + commitid = '' + return {'tag': tag, 'commitid': commitid} def getloginfo(self, port = None): @@ -395,6 +376,18 @@ def exec_shell(self, shell_cmd): else: self.faildone(logs) + def dingding(self, Robot, content): + data = { + "msgtype": "text", + "text": { + "content": content + } + } + try: + r = requests.post(url=Robot, data=json.dumps(data), headers=headers, timeout=2).json() + except Exception as err: + print('ERROR: notice dingding api error. %s' %(str(err))) + def done(self): self.updateTaskStatus() self.notice() @@ -419,17 +412,14 @@ def notexec(self, port = None): pass def makeUpdate(self): - code = self.check_code_update() - - if code: - self.addlog('INFO: check_code_update true') - self.code_update() + self.code_update() + if self.checkcommitid(): self.make_operation() self.tag_operation() self.backup_operation() self.write_commitid() else: - self.addlog('INFO: not update git code') + self.addlog('INFO: not make code') self.build_file_operation() self.addlog('INFO: tag: %s' %(self.tag)) @@ -438,88 +428,59 @@ def makeFallback(self): self.local_commitid() def makeExpansion(self): - self.getlastoktag() + self.tag = self.getlastokstatus()['tag'] + if self.tag == '': + self.faildone('getlastokstatus. not update ok. ') self.check_backup_operation() self.local_commitid() - - def getport(self): - shell_cmd = '''ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s@%s "supervisorctl status" |grep ^%s: |awk '{print $1}' |awk -F ':' '{print $2}' ''' %( - self.exec_user, self.host, self.project) - - Result = self.exec_shell(shell_cmd) - portlist = Result['log'].strip().split('\n') - pl = [] - for port in portlist: - if port == '': - return [''] - self.addlog('getport port: %s' %(port)) - pl.append(int(port)) - return pl - - - def check_code_update(self): - if not os.path.isdir('%s/%s' %(self.project_path, self.project) ): - if self.Type != 'go': - self.addlog('WARN: check_code_update. %s/%s directory does not exist. ' - %(self.project_path, self.project) ) - shell_cmd = 'git clone %s %s/%s' %(self.git, self.project_path, self.project) - Result = self.exec_shell(shell_cmd) - localCommitId = 'INFO: Not Commit Id' - else: + def code_update(self): + if self.Type == 'go': + shell_cmd = ''' rm -rf %s/%s ; git clone --depth=1 -b %s %s %s/%s && cd %s/%s && git log -n 1 --stat + ''' %(self.project_path, self.project, self.branch, self.git, self.project_path, self.project, self.project_path, self.project ) + self.exec_shell(shell_cmd) + elif os.path.isdir('%s/%s' %(self.project_path, self.project) ): shell_cmd = "cd %s/%s && git remote -v |grep fetch |awk '{print $2}'" %(self.project_path, self.project) Result = self.exec_shell(shell_cmd) localGit = Result['log'].strip() if localGit == self.git: - shell_cmd = "cd %s/%s && git rev-parse HEAD" %(self.project_path, self.project) - self.addlog('localCommitId: ') - Result = self.exec_shell(shell_cmd) - localCommitId = Result['log'].strip() + shell_cmd = ''' cd %s/%s && git reset --hard && git gc && git remote prune origin \ + && git fetch && git checkout %s && git reset --hard origin/%s \ + && git submodule init && git submodule update \ + && git log -n 1 --stat + ''' %(self.project_path, self.project, self.branch, self.branch) + self.exec_shell(shell_cmd) else: shell_cmd = 'rm -rf %s/%s' %(self.project_path, self.project) self.addlog(shell_cmd) - Result = self.exec_shell(shell_cmd) + self.exec_shell(shell_cmd) shell_cmd = 'git clone %s %s/%s' %(self.git, self.project_path, self.project) self.addlog(shell_cmd) - Result = self.exec_shell(shell_cmd) - localCommitId = 'localCommitId: new git' + self.exec_shell(shell_cmd) + else: + shell_cmd = 'git clone %s %s/%s' %(self.git, self.project_path, self.project) + self.addlog(shell_cmd) + self.exec_shell(shell_cmd) - shell_cmd = '''cd %s/%s && git ls-remote --heads origin refs/heads/%s''' %( - self.project_path, self.project, self.branch) - self.addlog('remoteCommitId: ') - Result = self.exec_shell(shell_cmd) - if not Result['log']: - self.faildone('check_code_update. %s/%s remote %s branch not existent. ' - %(self.project_path, self.project, self.branch) ) - remoteCommitId = Result['log'].strip().split()[0] - - self.commitid = remoteCommitId - - if localCommitId == remoteCommitId: - self.addlog('INFO: localCommitId = remoteCommitId\n' ) - if self.getlasttag(): - return False - self.addlog('INFO: getlastta False') - return True - else: - self.addlog('INFO: localCommitId != remoteCommitId\n' ) - return True + def checkcommitid(self): + shell_cmd = "cd %s/%s && git rev-parse HEAD" %(self.project_path, self.project) + Result = self.exec_shell(shell_cmd) + self.commitid = Result['log'].strip()[0:8] + laststatus = self.getlastokstatus() + lastcommitid = laststatus['commitid'] + lasttag = laststatus['tag'] - def code_update(self): - if self.Type == 'go': - shell_cmd = ''' rm -rf %s/%s ; git clone --depth=1 -b %s %s %s/%s && cd %s/%s && git log -n 1 --stat - ''' %(self.project_path, self.project, self.branch, self.git, self.project_path, self.project, self.project_path, self.project ) + if self.commitid == lastcommitid: + self.tag = lasttag + self.addlog('lastCommitId: %s' %(self.commitid) ) + self.addlog('lasttag: %s' %(self.tag) ) + return False else: - shell_cmd = ''' cd %s/%s && git reset --hard && git gc && git remote prune origin \ - && git fetch && git checkout %s && git reset --hard origin/%s \ - && git submodule init && git submodule update \ - && git log -n 1 --stat - ''' %(self.project_path, self.project, self.branch, self.branch) - self.exec_shell(shell_cmd) - return True + self.addlog('newCommitId: %s' %(self.commitid) ) + return True def local_commitid(self): @@ -534,6 +495,8 @@ def build_file_operation(self): %(self.project_path, self.project, self.tag) ) if self.Type == 'golang': + shell_cmd = "cd %s/%s-%s && rm -rf deploy-etc/ deploy-bin/etc && mkdir -p deploy-bin && git clone --depth=1 %s deploy-etc && cp -a deploy-etc/etc deploy-bin/etc " %(self.project_path, self.project, self.tag, self.supervisor.strip() ) + self.exec_shell(shell_cmd) shell_cmd = '''cd %s/%s-%s && cp -a startdata libs deploy-bin/ ''' %( self.project_path, self.project, self.tag) print(os.popen(shell_cmd).read()) @@ -541,7 +504,7 @@ def build_file_operation(self): ''' %(self.project_path, self.project, self.tag) print(os.popen(shell_cmd).read()) - self.addlog('---------------------------\n%s\n---------------------------' %self.config1) + self.addlog('---------------------------\n%s\n---------------------------' %self.supervisor) else: pass @@ -575,9 +538,6 @@ def write_commitid(self): self.exec_shell(shell_cmd) def backup_operation(self): - - #self.addlog('ls -dr %s/%s-%s-20* |awk "NR>8{print $1}" |xargs -i rm -rf {} ' %(self.project_path, self.project, self.project.split('_')[0]) ) - bak_delete_start_time = time.strftime('%Y-%m-%d %H:%M:%S') shell_cmd = '''ls -dr %s/%s-%s-20* 2>/dev/null |awk "NR>9{print $1}" |xargs -i rm -rf {} ''' %(self.project_path, self.project, self.project.split('_')[0]) @@ -603,7 +563,7 @@ def check_backup_operation(self): def check_status(self, port = None): if port is None: port = self.port - if self.isnginx == 'yes': + if self.checkport == 'yes': i = 0 results = '' while i < 60: @@ -634,18 +594,18 @@ def check_status(self, port = None): def http_check(self, port = None): if port is None: port = self.port - if self.ischeck == 'yes': + if self.checkhttp == 'get': i = 0 results = '' httpcontent = '' - url = 'http://%s:%s%s' %(self.host, port, self.checkurl) + url = 'http://%s:%s%s' %(self.host, port, self.httpurl) while i < 30: try: r = requests.get(url,timeout=2) httpstatus = r.status_code httpcontent = r.content - if httpstatus == int(self.statuscode): + if httpstatus == int(self.httpcode): results = 'ok' time.sleep(1) break @@ -768,7 +728,7 @@ def removeService(self, port = None): def increaseService(self, port = None): if port is None: port = self.port - if self.isnginx == 'yes': + if self.checkport == 'yes': pass def autotest(self, port = None): diff --git a/app/main/forms.py b/app/main/forms.py index c5861e5..447ac63 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -50,10 +50,10 @@ def writefile(path, content): def hostInit(project, host, Type): if Type == 'java': shell_cmd = '''ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s@%s "cp -a %s/tomcat8_install_template %s/%s " ''' %( - exec_user, host, host_path, host_path, project) + exec_user, host, remote_host_path, remote_host_path, project) else: - shell_cmd = '''ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s@%s "mkdir -p %s %s %s %s /data/golang/supervisor " ''' %( - exec_user, host, supervisor_log_path, host_path, go_host_path, jobs_host_path) + shell_cmd = '''ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s@%s "mkdir -p %s %s" ''' %( + exec_user, host, supervisor_log_path, remote_host_path) Result = shellcmd(shell_cmd) if Result['status'] != 'ok': return Result['log'] @@ -65,7 +65,7 @@ def deployConfig(project, host, ones, ones1, ones2): try: if ones.type in supervisord_list: # supervisor - supervisor_conf = ones2.config3.replace('$ip$',host).replace('$pnum$',ones1.variable1).replace('$env$',ones1.variable6) + supervisor_conf = ones2.supervisor.replace('$ip$',host).replace('$pnum$',ones1.pnum).replace('$env$',ones1.env) supervisor_conf_path = '%s/%s_%s_supervisor.conf' %(project_path, project, host) remote_supervisor_conf_path = '%s@%s:%s/%s.conf' %(exec_user, host, supervisor_conf_dir, project) writefile(supervisor_conf_path, supervisor_conf) @@ -81,33 +81,6 @@ def deployConfig(project, host, ones, ones1, ones2): Result = shellcmd(shell_cmd) if Result['status'] != 'ok': raise Exception(Result['log']) - - elif ones.type == 'java': - # tomcat server.xml - server_xml_path = '%s/%s_%s_server.xml' %(project_path, project, host) - remote_server_xml_path = '%s@%s:%s/%s/conf/server.xml' %(exec_user, host, host_path, project) - server_xml = ones2.config3.replace('$ip$', host) - writefile(server_xml_path, server_xml) - - shell_cmd = '''scp -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s %s > /dev/null ''' %( - server_xml_path, remote_server_xml_path) - Result = shellcmd(shell_cmd) - if Result['status'] != 'ok': - raise Exception(Result['log']) - - # tomcat catalina.sh - catalina_sh_path = '%s/%s_%s_catalina.sh' %(project_path, project, host) - remote_catalina_sh_path = '%s@%s:%s/%s/bin/catalina.variable' %(exec_user, host, host_path, project) - catalina_sh = ones2.config2.replace('$jxmport$',ones1.variable1 - ).replace('$config_dir$', ones2.config4 - ).replace('$env$', ones.environment) - writefile(catalina_sh_path, catalina_sh) - - shell_cmd = '''scp -o StrictHostKeyChecking=no -o ConnectTimeout=2 %s %s > /dev/null ''' %( - catalina_sh_path, remote_catalina_sh_path) - Result = shellcmd(shell_cmd) - if Result['status'] != 'ok': - raise Exception(Result['log']) return 'ok' except Exception as err: return str(err) diff --git a/app/main/views.py b/app/main/views.py index 7fea7cb..0fb3801 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -371,8 +371,7 @@ def hostlist(): return json.dumps([['sql','error','null','null']]) rl = [] for i in ones1: - rl.append([i.ip, i.hostname, i.project_name, Type, i.variable1, i.variable2, i.variable3, - i.variable4, i.variable5, i.variable6, i.variable7, i.variable8, i.variable9]) + rl.append([i.ip, i.hostname, i.project_name, Type, i.pnum, i.env, i.checkstatus, i.checktime, i.commitid, i.updatestatus, i.updatetime ]) return json.dumps(rl) @@ -403,9 +402,9 @@ def iplistall(): @main.route("/hostlisterr", methods=["GET", "POST"]) def hostlisterr(): try: - ones = serverinfo.query.filter( serverinfo.variable2 != 'RUNNING', - serverinfo.variable2 != 'SSHOK', - serverinfo.variable2 != 'null' + ones = serverinfo.query.filter( serverinfo.checkstatus != 'RUNNING', + serverinfo.checkstatus != 'SSHOK', + serverinfo.checkstatus != 'null' ).order_by(serverinfo.project_name).all() except: return json.dumps([['sql','error','null','null']]) @@ -413,8 +412,8 @@ def hostlisterr(): Type = 'null' for i in ones: - rl.append([i.ip, i.hostname, i.project_name, Type, i.variable1, i.variable2, i.variable3, - i.variable4, i.variable5, i.variable6, i.variable7, i.variable8, i.variable9]) + rl.append([i.ip, i.hostname, i.project_name, Type, i.pnum, i.checkstatus, i.checktime, + i.commitid, i.updatestatus, i.updatetime]) return json.dumps(rl) @main.route("/port_list", methods=["GET", "POST"]) @@ -446,14 +445,12 @@ def project_list(): def project_info(): project = request.args.get("project", "null") if project == "null": - return json.dumps(['project null', 'environment', 'git', 'branch', 'type', 'port', 'istag', 'isnginx', 'business', 'ischeck', 'checkurl', 'statuscode']) + return json.dumps(['business', 'environment', 'project null', 'type', 'port', 'git', 'branch']) try: ones = projectinfo.query.filter(projectinfo.project_name == project).first() except: - return json.dumps(['sql error', 'environment', 'git', 'branch', 'type', 'port', 'istag', 'isnginx', 'business', 'ischeck', 'checkurl', 'statuscode']) - rl = [ones.project, ones.environment, ones.git, ones.branch, ones.type, ones.port, - ones.make.replace('"','"').replace("'",'''), ones.istag, ones.isnginx, - ones.business, ones.ischeck, ones.checkurl, ones.statuscode] + return json.dumps(['business', 'environment', 'sql error', 'type', 'port', 'git', 'branch']) + rl = [ ones.business, ones.environment, ones.project, ones.type, ones.port, ones.git, ones.branch] return json.dumps(rl) @@ -463,11 +460,10 @@ def projectinfoall(): try: ones = projectinfo.query.all() except: - return json.dumps( {'environment_project null':['git', 'branch', 'type', 'port', 'make', 'istag', 'isnginx', 'business', 'ischeck', 'checkurl', 'statuscode']}) + return json.dumps( {'environment_project null':['git', 'branch', 'type', 'port', 'business']}) rl = {} for i in ones: - rl['%s_%s' %(i.environment, i.project)] = [i.git, i.branch, i.type, i.port, i.make.replace('"','"').replace("'",'''), - i.istag, i.isnginx, i.business, i.ischeck, i.checkurl, i.statuscode] + rl['%s_%s' %(i.environment, i.project)] = [i.git, i.branch, i.type, i.port, i.business] return json.dumps(rl) @@ -483,15 +479,17 @@ def config_info(): except: return json.dumps({'sql error':'config'}) - rl = [ ['config1', ones.config1], - ['config2', ones.config2], - ['config3', ones.config3], - ['config4', ones.config4], - ['config5', ones.config5], - ['服务主要功能', ones.config6], - ['主要使用的后端服务', ones.config7], - ['出问题后影响', ones.config8], - ['其他', ones.config9] + rl = [ ['make', ones.make], + ['supervisor', ones.supervisor], + ['config', ones.config], + ['remarks', ones.remarks], + ['startcmd', ones.startcmd], + ['packfile', ones.packfile], + ['istag', ones.istag], + ['checkport', ones.checkport], + ['checkhttp', ones.checkhttp], + ['httpurl', ones.httpurl], + ['httpcode', ones.httpcode] ] return json.dumps(rl) @@ -502,23 +500,17 @@ def add_project(): R = {'status':'ok', 'log':'', 'data':''} try: - project = request.form.get('project', "null").strip() + business = request.form.get('business', "null").strip() environment = request.form.get('environment', "null").strip() - git = request.form.get('git', "null").strip() - branch = request.form.get('branch', "null").strip() + project = request.form.get('project', "null").strip() program_type = request.form.get('type', "null").strip() port = str(request.form.get('port', "0")).strip() - make = str(request.form.get('make', "null")).strip() - istag = request.form.get('istag', "null").strip() - isnginx = request.form.get('isnginx', "null").strip() - business = request.form.get('business', "null").strip() - ischeck = request.form.get('check', "null").strip() - checkurl = request.form.get('checkurl', "null").strip() - statuscode = request.form.get('statuscode', "null").strip() + git = request.form.get('git', "null").strip() + branch = request.form.get('branch', "null").strip() if not port: port = '0' - if project == "null" or environment == "null" or branch == "null" or program_type == "null" or git == "null" or istag == "null": + if project == "null" or environment == "null" or branch == "null" or program_type == "null" or git == "null": raise Exception('ERROR: parameter error') project_name = environment + '_' + project @@ -527,76 +519,50 @@ def add_project(): if ones != None: raise Exception('ERROR: project already exists') newproject = projectinfo( project_name = project_name, - project = project, - environment = environment, - branch = branch, - type = program_type, - git = git, - port = port, - make = make, - istag=istag, - isnginx=isnginx, - business=business, - ischeck=ischeck, - checkurl=checkurl, - statuscode=statuscode + business = business, + environment = environment, + project = project, + type = program_type, + port = port, + git = git, + branch = branch ) db.session.add(newproject) db.session.commit() - - config1 = '' - config2 = '' - config3 = '' - config4 = '' - config5 = '' - config6 = '' - config7 = '' - config8 = '' - config9 = '' - config10 = '' - - if environment == 'online': - ZUIYOU_ENV = 'production' - projectenv = project - else: - ZUIYOU_ENV = environment - projectenv = '%s-%s' %(project, environment) - if program_type == 'python': - config3 = supervisor_python_conf + supervisor = supervisor_python_conf if program_type == 'nodejs': - config3 = supervisor_nodejs_conf + supervisor = supervisor_nodejs_conf elif program_type == 'go' or program_type == 'golang': - config3 = supervisor_go_conf + supervisor = supervisor_go_conf elif program_type == 'sh': - config3 = supervisor_sh_conf + supervisor = supervisor_sh_conf elif program_type == 'java': - config2 = catalina_sh - config3 = server_xml + supervisor = catalina_sh + config = server_xml - config3 = config3.replace('$USER$', exec_user - ).replace('$HOST_PATH$', host_path - ).replace('$port$', port - ).replace('$project$', project - ).replace('$environment$',environment - ).replace('$supervisor_log_path$', supervisor_log_path - ).replace('$ZUIYOU_ENV$', ZUIYOU_ENV - ).replace('$project-env$', projectenv - ).replace('$ajpport$', str(int(port)-105) - ).replace('$shutdownport$', str(int(port)-75) ) + supervisor = supervisor.replace('$USER$', exec_user + ).replace('$HOST_PATH$', remote_host_path + ).replace('$port$', port + ).replace('$project$', project + ).replace('$environment$', environment + ).replace('$supervisor_log_path$', supervisor_log_path + ).replace('$ajpport$', str(int(port)-105) + ).replace('$shutdownport$', str(int(port)-75) ) configadd = project_config( project_name = project_name, - config1 = config1, - config2 = config2, - config3 = config3, - config4 = config4, - config5 = config5, - config6 = config6, - config7 = config7, - config8 = config8, - config9 = config9, - config10 = config10 ) + make = 'sh deploy_make.sh', + supervisor = supervisor, + config = '', + remarks = 'remarks', + startcmd = '', + packfile = '', + istag = 'no', + checkport = 'no', + checkhttp = 'no', + httpurl = '/', + httpcode = '200') db.session.add(configadd) db.session.commit() @@ -611,27 +577,20 @@ def add_project(): def add_host(): R = {'status':'ok', 'log':'', 'data':''} try: - project = request.form.get('project', "null").strip() - hostname = request.form.get('hostname', "null").strip() - host = request.form.get('host', "null").strip() - variable1 = request.form.get('variable1', "1").strip() - variable2 = request.form.get('variable2', "null").strip() - variable3 = request.form.get('variable3', "null").strip() - variable4 = request.form.get('variable4', "null").strip() - variable5 = request.form.get('variable5', "null").strip() - variable6 = request.form.get('variable6', "").strip() - variable7 = request.form.get('variable7', "null").strip() - variable8 = request.form.get('variable8', "null").strip() - variable9 = request.form.get('variable9', "null").strip() + project = request.form.get('project', "null").strip() + hostname = request.form.get('hostname', "null").strip() + host = request.form.get('host', "null").strip() + pnum = request.form.get('pnum', "1" ).strip() + env = request.form.get('env', "" ).strip() if project == "null" or hostname == "null" or host == "null" or project == "" or hostname == "" or host == "": raise Exception('ERROR: parameter error') ones1 = serverinfo.query.filter(serverinfo.project_name == project, serverinfo.ip == host).all() if len(ones1) != 0: raise Exception('ERROR: host exist.') - if variable1 == '': - variable1 = '1' + if pnum == '': + pnum = '1' - newserver = serverinfo(project, hostname, host, variable1, variable2, variable3, variable4, variable5, variable6, variable7, variable8, variable9) + newserver = serverinfo(project, hostname, host, pnum, env, 'checkstatus', 'checktime', 'commitid', 'updatestatus', 'updatetime') db.session.add(newserver) db.session.commit() @@ -682,18 +641,16 @@ def del_host(): def update_host(): R = {'status':'ok', 'log':'', 'data':''} try: - project = request.form.get('project', 'null').strip() - ip = request.form.get('hostip', 'null').strip() - hostname = request.form.get('hostname', 'null').strip() - variable1 = request.form.get('variable1', 'null').strip() - variable2 = request.form.get('variable2', 'null').strip() - variable3 = request.form.get('variable3', 'null').strip() - variable4 = request.form.get('variable4', 'null').strip() - variable5 = request.form.get('variable5', 'null').strip() - variable6 = request.form.get('variable6', '').strip() - variable7 = request.form.get('variable7', 'null').strip() - variable8 = request.form.get('variable8', 'null').strip() - variable9 = request.form.get('variable9', 'null').strip() + project = request.form.get('project', 'null').strip() + hostname = request.form.get('hostname', 'null').strip() + ip = request.form.get('hostip', 'null').strip() + pnum = request.form.get('pnum', '1' ).strip() + env = request.form.get('env', '' ).strip() + checkstatus = request.form.get('checkstatus', 'null').strip() + checktime = request.form.get('checktime', 'null').strip() + commitid = request.form.get('commitid', 'null').strip() + updatestatus = request.form.get('updatestatus','null').strip() + updatetime = request.form.get('updatetime', 'null').strip() if project == 'null' or ip == 'null': raise Exception('ERROR: host null') @@ -702,9 +659,9 @@ def update_host(): serverinfo.query.filter( serverinfo.project_name == project, serverinfo.ip == ip ).update({ - "hostname": hostname, - "variable1":variable1, - "variable6":variable6 + "hostname" : hostname, + "pnum" : pnum, + "env" : env }) db.session.commit() except Exception as err: @@ -783,7 +740,7 @@ def deploy(): s = os.system( '''(cd %s/app/main/;nohup python deploy.py "%s" "%s" "%s" "%s" "%s" "%s" "%s") >>%s/%s.log 2>&1 &''' %(sys.path[0], project, tag, taskid, host, operation, currentuser, 'reason', log_path, project) ) R['output'] = 'INFO: Please wait. %s in progress' %(operation) - newupdateoperation = updateoperation(taskid, project, host, tag, operating_time, operation, R['output'], currentuser) + newupdateoperation = updateoperation(taskid, project, host, tag, operating_time, operation, currentuser, R['status'], 'commitid') db.session.add(newupdateoperation) db.session.commit() except Exception as err: @@ -825,7 +782,7 @@ def online_log_time(): return json.dumps([['null', 'null', 'null', 'null', 'ERROR: SQL not correct']]) rl = [] for i in ones: - rl.append([i.operation, i.taskid, i.tag, i.project_name, i.loginfo, i.user]) + rl.append([i.operation, i.taskid, i.tag, i.project_name, i.status, i.user, i.commitid]) return json.dumps(rl) @@ -841,7 +798,7 @@ def online_log_all(): return json.dumps([['null', 'null', 'null', 'null', 'ERROR: SQL not correct']]) rl = [] for i in ones: - rl.append([i.operation, i.taskid, i.tag, i.project_name, i.loginfo, i.user]) + rl.append([i.operation, i.taskid, i.tag, i.project_name, i.status, i.user, i.commitid]) return json.dumps(rl) @@ -855,7 +812,7 @@ def online_tag(): try: ones = updateoperation.query.filter( updateoperation.project_name == project, updateoperation.operation.in_ ([ 'serviceUpdate']), - updateoperation.loginfo == 'ok' + updateoperation.status == 'ok' ).order_by(updateoperation.taskid.desc()).limit(15) except: return json.dumps(['ERROR: SQL not correct']) @@ -873,7 +830,7 @@ def current_tag(): try: ones = updateoperation.query.filter( updateoperation.project_name == project, updateoperation.operation.in_ ([ 'serviceUpdate','serviceFallback','serviceFastback']), - updateoperation.loginfo == 'ok' + updateoperation.status == 'ok' ).order_by(updateoperation.taskid.desc()).limit(2) rl = [ones[0].tag] except: @@ -891,7 +848,7 @@ def lastlog(): return json.dumps([['project','null']]) try: ones = updateoperation.query.filter( updateoperation.project_name == project, - updateoperation.loginfo.notlike('%Repeat the update, Please wait%') + updateoperation.status != 'wait', ).order_by(updateoperation.taskid.desc()).limit(1) taskid = ones[0].taskid ones = updatelog.query.filter(updatelog.taskid == taskid ).all() @@ -909,20 +866,14 @@ def lastlog(): def update_project(): R = {'status':'ok', 'log':'', 'data':''} try: - project = request.form.get('project', "null").strip() + business = request.form.get('business', "null").strip() environment = request.form.get('environment', "null").strip() - git = request.form.get('git', "null").strip() - branch = request.form.get('branch', "null").strip() + project = request.form.get('project', "null").strip() program_type = request.form.get('type', "null").strip() port = request.form.get('port', "0").strip() - make = request.form.get('make', "null").strip() - istag = request.form.get('istag', "null").strip() - isnginx = request.form.get('isnginx', "null").strip() - business = request.form.get('business', "null").strip() - ischeck = request.form.get('check', "null").strip() - checkurl = request.form.get('checkurl', "null").strip() - statuscode = request.form.get('statuscode', "null").strip() - if project == "null" or environment == "null" or branch == "null" or program_type == "null" or git == "null" or istag == "null": + git = request.form.get('git', "null").strip() + branch = request.form.get('branch', "null").strip() + if project == "null" or environment == "null" or branch == "null" or program_type == "null" or git == "null": raise Exception('ERROR: parameter error') project_name = environment + '_' + project @@ -930,23 +881,17 @@ def update_project(): if currentuser not in adminuser and environment == 'online': raise Exception('ERROR: update_project no authority') - logging.warning('update_project: %s, %s, %s, %s, %s, %s, %s, %s' %( - currentuser, project_name, git, branch, program_type, port, make, business) ) + logging.warning('update_project: %s, %s, %s, %s, %s, %s, %s' %( + currentuser, business, program_type, project_name, git, branch, port) ) projectinfo.query.filter(projectinfo.project_name == project_name).update({ - "project" : project, + "business" : business, "environment" : environment, - "branch" : branch, - "type" : program_type, - "git" : git, - "port" : port, - "make" : make, - "istag" : istag, - "isnginx" : isnginx, - "business" : business, - "ischeck" : ischeck, - "checkurl" : checkurl, - "statuscode" : statuscode + "project" : project, + "type" : program_type, + "port" : port, + "git" : git, + "branch" : branch }) db.session.commit() @@ -961,32 +906,34 @@ def update_project(): def update_config(): R = {'status':'ok', 'log':'', 'data':''} try: - project_name = request.form.get('project', "null").strip() - config1 = request.form.get('config1', "null").strip() - config2 = request.form.get('config2', "null").strip() - config3 = request.form.get('config3', "null").strip() - config4 = request.form.get('config4', "null").strip() - config5 = request.form.get('config5', "null").strip() - config6 = request.form.get('config6', "null").strip() - config7 = request.form.get('config7', "null").strip() - config8 = request.form.get('config8', "null").strip() - config9 = request.form.get('config9', "null").strip() - config10 = request.form.get('config10', "null").strip() + project_name = request.form.get('project', "null").strip() + make = request.form.get('make', "null").strip() + supervisor = request.form.get('supervisor', "null").strip() + config = request.form.get('config', "null").strip() + remarks = request.form.get('remarks', "null").strip() + startcmd = request.form.get('startcmd', "null").strip() + packfile = request.form.get('packfile', "null").strip() + istag = request.form.get('istag', "null").strip() + checkport = request.form.get('checkport', "null").strip() + checkhttp = request.form.get('checkhttp', "null").strip() + httpurl = request.form.get('httpurl', "null").strip() + httpcode = request.form.get('httpcode', "null").strip() if project_name == "null": raise Exception('ERROR: project error') currentuser = current_user.username logging.warning('update_config: %s, %s' %(currentuser, project_name) ) project_config.query.filter(project_config.project_name == project_name).update({ - "config1" : config1, - "config2" : config2, - "config3" : config3, - "config4" : config4, - "config5" : config5, - "config6" : config6, - "config7" : config7, - "config8" : config8, - "config9" : config9, - "config10" : config10 }) + "make" : make, + "supervisor" : supervisor, + "config" : config, + "remarks" : remarks, + "startcmd" : startcmd, + "packfile" : packfile, + "istag" : istag, + "checkport" : checkport, + "checkhttp" : checkhttp, + "httpurl" : httpurl, + "httpcode" : httpcode }) db.session.commit() except Exception as err: @@ -1003,7 +950,7 @@ def online_statistics(): monday=datetime.date.today() - datetime.timedelta(days=datetime.date.today().weekday()) monday_timestamp=time.mktime(time.strptime(monday.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S')) - online_total=updateoperation.query.filter(updateoperation.project_name.like('online_%'),updateoperation.loginfo.notlike('%ERROR%'),updateoperation.taskidmonday_timestamp-2419200).all() + online_total=updateoperation.query.filter(updateoperation.project_name.like('online_%'),updateoperation.status.notlike('error'),updateoperation.taskidmonday_timestamp-2419200).all() statistical_result = {} @@ -1202,16 +1149,8 @@ def expansion(): time.sleep(5) if status != 'ok': raise Exception('ERROR: expansion host %s ssh fail. %s' %(host, expansionInfo)) - variable1 = "1" - variable2 = "" - variable3 = "" - variable4 = "" - variable5 = "" - variable6 = "" - variable7 = "" - variable8 = "" - variable9 = "" - newserver = serverinfo(project, hostname, host, variable1, variable2, variable3, variable4, variable5, variable6, variable7, variable8, variable9) + pnum = "1" + newserver = serverinfo(project, hostname, host, pnum, 'checkstatus', 'checktime', 'commitid', 'updatestatus', 'updatetime') db.session.add(newserver) db.session.commit() ones = projectinfo.query.filter(projectinfo.project_name == project ).first() @@ -1245,7 +1184,7 @@ def expansion(): except Exception as err: logging.error(str(err)) try: - newupdateoperation = updateoperation(taskid, project, host, tag, rtime, operation, R['output'], currentuser) + newupdateoperation = updateoperation(taskid, project, host, tag, rtime, operation, currentuser, R['status'], 'commitid') db.session.add(newupdateoperation) db.session.commit() except Exception as err: diff --git a/app/models.py b/app/models.py index efd6c35..a17d5d9 100644 --- a/app/models.py +++ b/app/models.py @@ -35,29 +35,25 @@ class serverinfo(db.Model): project_name = db.Column(db.String(64) , index=True) hostname = db.Column(db.String(64)) ip = db.Column(db.String(64)) - variable1 = db.Column(db.String(64)) - variable2 = db.Column(db.String(64)) - variable3 = db.Column(db.String(64)) - variable4 = db.Column(db.String(64)) - variable5 = db.Column(db.String(64)) - variable6 = db.Column(db.String(64)) - variable7 = db.Column(db.String(64)) - variable8 = db.Column(db.String(64)) - variable9 = db.Column(db.String(64)) - - def __init__(self, project_name, hostname, ip, variable1, variable2, variable3, variable4, variable5, variable6, variable7, variable8, variable9): + pnum = db.Column(db.String(32)) + env = db.Column(db.String(3200)) + checkstatus = db.Column(db.String(64)) + checktime = db.Column(db.String(64)) + commitid = db.Column(db.String(64)) + updatestatus = db.Column(db.String(64)) + updatetime = db.Column(db.String(64)) + + def __init__(self, project_name, hostname, ip, pnum, env, checkstatus, checktime, commitid, updatestatus, updatetime): self.project_name = project_name self.hostname = hostname self.ip = ip - self.variable1 = variable1 - self.variable2 = variable2 - self.variable3 = variable3 - self.variable4 = variable4 - self.variable5 = variable5 - self.variable6 = variable6 - self.variable7 = variable7 - self.variable8 = variable8 - self.variable9 = variable9 + self.pnum = pnum + self.env = env + self.checkstatus = checkstatus + self.checktime = checktime + self.commitid = commitid + self.updatestatus = updatestatus + self.updatetime = updatetime class userservicegroup(db.Model): @@ -75,63 +71,55 @@ def __init__(self, username, servicegroup, permissions): class projectinfo(db.Model): __tablename__ = 'projectinfo' project_name = db.Column(db.String(64), primary_key=True) - project = db.Column(db.String(64)) + business = db.Column(db.String(40)) environment = db.Column(db.String(64)) - branch = db.Column(db.String(64)) + project = db.Column(db.String(64)) type = db.Column(db.String(50)) - git = db.Column(db.String(1024)) port = db.Column(db.Integer) - make = db.Column(db.Text) - istag = db.Column(db.String(10)) - isnginx = db.Column(db.String(10)) - business = db.Column(db.String(40)) - ischeck = db.Column(db.String(10)) - checkurl = db.Column(db.String(300)) - statuscode = db.Column(db.String(8)) + git = db.Column(db.String(1024)) + branch = db.Column(db.String(64)) - def __init__(self, project_name, project, environment, branch, type, git, port, make, istag, isnginx, business, ischeck, checkurl, statuscode): + + def __init__(self, project_name, business, environment, project, type, port, git, branch): self.project_name = project_name - self.project = project + self.business = business self.environment = environment - self.branch = branch + self.project = project self.type = type - self.git = git self.port = port - self.make = make - self.istag = istag - self.isnginx = isnginx - self.business = business - self.ischeck = ischeck - self.checkurl = checkurl - self.statuscode = statuscode + self.git = git + self.branch = branch class project_config(db.Model): __tablename__ = 'project_config' project_name = db.Column(db.String(64), primary_key=True) - config1 = db.Column(db.Text) - config2 = db.Column(db.Text) - config3 = db.Column(db.Text) - config4 = db.Column(db.Text) - config5 = db.Column(db.Text) - config6 = db.Column(db.Text) - config7 = db.Column(db.Text) - config8 = db.Column(db.Text) - config9 = db.Column(db.Text) - config10 = db.Column(db.Text) - - def __init__(self, project_name, config1, config2, config3, config4, config5, config6, config7, config8, config9, config10): + make = db.Column(db.Text) + supervisor = db.Column(db.Text) + config = db.Column(db.Text) + remarks = db.Column(db.Text) + startcmd = db.Column(db.String(200)) + packfile = db.Column(db.String(200)) + istag = db.Column(db.String(10)) + checkport = db.Column(db.String(10)) + checkhttp = db.Column(db.String(10)) + httpurl = db.Column(db.String(2000)) + httpcode = db.Column(db.String(8)) + + + def __init__(self, project_name, make, supervisor, config, remarks, startcmd, packfile, istag, checkport, checkhttp, httpurl, httpcode): self.project_name = project_name - self.config1 = config1 - self.config2 = config2 - self.config3 = config3 - self.config4 = config4 - self.config5 = config5 - self.config6 = config6 - self.config7 = config7 - self.config8 = config8 - self.config9 = config9 - self.config10 = config10 + self.make = make + self.supervisor = supervisor + self.config = config + self.remarks = remarks + self.startcmd = startcmd + self.packfile = packfile + self.istag = istag + self.checkport = checkport + self.checkhttp = checkhttp + self.httpurl = httpurl + self.httpcode = httpcode class updatelog(db.Model): @@ -163,18 +151,20 @@ class updateoperation(db.Model): tag = db.Column(db.String(64)) rtime = db.Column(db.String(32)) operation = db.Column(db.String(64)) - loginfo = db.Column(db.String(6400)) user = db.Column(db.String(50)) + status = db.Column(db.String(20)) + commitid = db.Column(db.String(1024)) - def __init__(self, taskid, project_name, hostlist, tag, rtime, operation, loginfo, user): + def __init__(self, taskid, project_name, hostlist, tag, rtime, operation, user, status, commitid): self.taskid = taskid self.project_name = project_name self.hostlist = hostlist self.tag = tag self.rtime = rtime self.operation = operation - self.loginfo = loginfo self.user = user + self.status = status + self.commitid = commitid class workorder(db.Model): diff --git a/app/static/ops.js b/app/static/ops.js index 171e591..610e171 100644 --- a/app/static/ops.js +++ b/app/static/ops.js @@ -44,18 +44,12 @@ function push_add_host_table(p){ } $.getJSON('/project_info', param, function(data){ var htm=['']; - if (data[4]=='python' || data[4]=='nodejs'){ - htm.push(''); - } else { - htm.push(''); - } + htm.push(''); htm.push(''); htm.push(''); htm.push(''); - if ( data[4]=='python' || data[4]=='nodejs'){ - htm.push(''); - } - htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); htm.push(''); htm.push('
hostnameippnumenvadd host
hostnameipenvadd host
hostnameippnumenvadd host
'+''+''+''+''+''+''+''+''+''+''+''+'
'); @@ -92,19 +86,13 @@ $("body").on('click', '#open_edit_host', function(){ $("body").on('click', '#add_project', function(){ if (confirm('请确认项目信息')) { - var add_type = $('#add_type').val() - var add_nproject = $('#add_nproject').val() + var add_business = $('#add_business').val() var add_environment = $('#add_environment').val() + var add_project = $('#add_nproject').val() + var add_type = $('#add_type').val() + var add_port = $('#add_port').val() var add_git = $('#add_git').val() var add_branch = $('#add_branch').val() - var add_port = $('#add_port').val() - var add_make = $('#add_make').val() - var add_istag = $('#add_istag').val() - var add_isnginx = $('#add_isnginx').val() - var add_business = $('#add_business').val() - var add_check = $('#add_check').val() - var add_checkurl = $('#add_checkurl').val() - var add_statuscode = $('#add_statuscode').val() if(!add_business ){ alert('business null'); @@ -119,7 +107,7 @@ $("body").on('click', '#add_project', function(){ alert('git branch null'); return false; } - if(!add_nproject ){ + if(!add_project ){ alert('project null'); return false; } @@ -131,10 +119,6 @@ $("body").on('click', '#add_project', function(){ alert('git addr null'); return false; } - if(!add_istag){ - alert('tag yes/no'); - return false; - } if(add_type == 'nodejs'){ if(add_port < 3000 || add_port >5000){ alert('python port [3000 - 5000]'); @@ -143,19 +127,13 @@ $("body").on('click', '#add_project', function(){ } var param = { - project: add_nproject, + business:add_business, environment: add_environment, - branch: add_branch, + project: add_project, type: add_type, port: add_port, git: add_git, - make: add_make, - istag: add_istag, - isnginx: add_isnginx, - business:add_business, - check: add_check, - checkurl: add_checkurl, - statuscode: add_statuscode, + branch: add_branch } $.post('/add_project', param, function(data){ @@ -173,29 +151,23 @@ $("body").on('click', '#add_project', function(){ $("body").on('click', '#update_project', function(){ if (confirm('请确认项目信息')) { - var add_type = $('#add_type').val() - var add_nproject = $('#add_nproject').val() + var add_business = $('#add_business').val() var add_environment = $('#add_environment').val() - var add_git = $('#add_git').val() - var add_branch = $('#add_branch').val() - var add_port = $('#add_port').val() - var add_make = $('#add_make').val() - var add_istag = $('#add_istag').val() - var add_isnginx = $('#add_isnginx').val() - var add_business = $('#add_business').val() - var add_check = $('#add_check').val() - var add_checkurl = $('#add_checkurl').val() - var add_statuscode = $('#add_statuscode').val() + var add_project = $('#add_nproject').val() + var add_type = $('#add_type').val() + var add_port = $('#add_port').val() + var add_git = $('#add_git').val() + var add_branch = $('#add_branch').val() - if(!add_environment ){ + if(!add_environment){ alert('environment null'); return false; } - if(!add_branch ){ + if(!add_branch){ alert('git branch null'); return false; } - if(!add_nproject ){ + if(!add_project){ alert('project null'); return false; } @@ -207,25 +179,14 @@ $("body").on('click', '#update_project', function(){ alert('git addr null'); return false; } - if(!add_istag){ - alert('tag yes/no'); - return false; - } - var param = { - project: add_nproject, + business: add_business, environment: add_environment, - branch: add_branch, + project: add_project, type: add_type, port: add_port, git: add_git, - make: add_make, - istag: add_istag, - isnginx: add_isnginx, - business: add_business, - check: add_check, - checkurl: add_checkurl, - statuscode: add_statuscode, + branch: add_branch, } $.post('/update_project', param, function(data){ @@ -256,29 +217,19 @@ function push_add_project_table(){ htm.push(''); htm.push(''); - htm.push(''); - htm.push('type:'); - htm.push(''+''+''); - htm.push(''); - - htm.push(''); - htm.push('project:'); - htm.push(''+''+''); - htm.push(''); - htm.push(''); htm.push('environment:'); htm.push(''+''+''); htm.push(''); htm.push(''); - htm.push('git:'); - htm.push(''+''+''); + htm.push('project:'); + htm.push(''+''+''); htm.push(''); htm.push(''); - htm.push('branch:'); - htm.push(''+''+''); + htm.push('type:'); + htm.push(''+''+''); htm.push(''); htm.push(''); @@ -287,37 +238,15 @@ function push_add_project_table(){ htm.push(''); htm.push(''); - htm.push('make:'); - htm.push(''+''+''); - htm.push(''); - - htm.push(''); - htm.push('tag:'); - htm.push(''+''+''); - htm.push(''); - - htm.push(''); - htm.push('Nginx'); - htm.push(''+''+''); - htm.push(''); - - - htm.push(''); - htm.push('httpCheck:'); - htm.push(''+''+''); - htm.push(''); - - htm.push(''); - htm.push('checkURL:'); - htm.push(''+''+''); + htm.push('git:'); + htm.push(''+''+''); htm.push(''); htm.push(''); - htm.push('statusCode:'); - htm.push(''+''+''); + htm.push('branch:'); + htm.push(''+''+''); htm.push(''); - htm.push(''); htm.push(''); htm.push(''); @@ -333,30 +262,16 @@ function push_add_project_table(){ $("body").on('click', '#add_host', function(){ if (confirm('确认提交?')) { var add_hostname = $('#add_hostname').val() - var add_ip = $('#add_ip').val() - var add_project = $('#add_host').attr('project') - var add_variable1 = $('#add_variable1').val() - var add_variable2 = $('#add_variable2').val() - var add_variable3 = $('#add_variable3').val() - var add_variable4 = $('#add_variable4').val() - var add_variable5 = $('#add_variable5').val() - var add_variable6 = $('#add_variable6').val() - var add_variable7 = $('#add_variable7').val() - var add_variable8 = $('#add_variable8').val() - var add_variable9 = $('#add_variable9').val() + var add_ip = $('#add_ip').val() + var add_project = $('#add_host').attr('project') + var add_pnum = $('#add_pnum').val() + var add_env = $('#add_env').val() var param = { hostname: add_hostname, host: add_ip, project: add_project, - variable1: add_variable1, - variable2: add_variable2, - variable3: add_variable3, - variable4: add_variable4, - variable5: add_variable5, - variable6: add_variable6, - variable7: add_variable7, - variable8: add_variable8, - variable9: add_variable9 + pnum: add_pnum, + env: add_env } $.post('/add_host', param, function(data){ @@ -436,20 +351,20 @@ $("body").on('click', '#add_user', function(){ $("body").on('click', '#update_host', function(){ - var num = $(this).attr('i') - var project = $(this).attr('project') + var num = $(this).attr('i') + var project = $(this).attr('project') var hostname = $('#hostname'+num).val() - var hostip = $('#hostip'+num).val() - var variable1 = $('#variable1'+num).val() - var variable6 = $('#variable6'+num).val() + var hostip = $('#hostip'+num).val() + var pnum = $('#pnum'+num).val() + var env = $('#env'+num).val() if (confirm('请确认更新: '+host)) { var param = { hostip: hostip, hostname: hostname, project: project, - variable1: variable1, - variable6: variable6, + pnum: pnum, + env: env } $.post('/update_host', param, function(data){ host_list_table(project) @@ -525,29 +440,6 @@ $("#back_submit").on('click', function(){ }); }); -//$("#back_submit").on('click', function(){ -// var p = $('#ipt_project').val() -// if (p != undefined){ -// var param = { -// project: p, -// operation: 'serviceFallback', -// tag: $('#select_tag').val(), -// }; -// $.getJSON('/lock_check', param, function(data){ -// if(data['status'] == "ok"){ -// if (confirm('请确认回滚'+ p +'?')) { -// updateonline(param) -// }; -// }else{ -// alert(data['user'] + '正在操作,请勿重复执行!') -// } -// }); -// } -// else{ -// alert('project_name null'); -// }; -//}); - $("body").on('click', '#btn_submit', function(){ @@ -794,11 +686,6 @@ function project_info(p){ htm.push(''); htm.push('Business line:'); - htm.push(''+data[9]+''); - htm.push(''); - - htm.push(''); - htm.push('project:'); htm.push(''+data[0]+''); htm.push(''); @@ -808,55 +695,30 @@ function project_info(p){ htm.push(''); htm.push(''); - htm.push('git:'); + htm.push('project:'); htm.push(''+data[2]+''); htm.push(''); htm.push(''); - htm.push('branch:'); + htm.push('type:'); htm.push(''+data[3]+''); htm.push(''); htm.push(''); - htm.push('type:'); + htm.push('port:'); htm.push(''+data[4]+''); htm.push(''); htm.push(''); - htm.push('port:'); + htm.push('git:'); htm.push(''+data[5]+''); htm.push(''); htm.push(''); - htm.push('make:'); + htm.push('branch:'); htm.push(''+data[6]+''); htm.push(''); - htm.push(''); - htm.push('tag:'); - htm.push(''+data[7]+''); - htm.push(''); - - htm.push(''); - htm.push('isnginx:'); - htm.push(''+data[8]+''); - htm.push(''); - - htm.push(''); - htm.push('httpCheck:'); - htm.push(''+data[10]+''); - htm.push(''); - - htm.push(''); - htm.push('checkURL:'); - htm.push(''+data[11]+''); - htm.push(''); - - htm.push(''); - htm.push('statusCode:'); - htm.push(''+data[12]+''); - htm.push(''); - htm.push(''); htm.push(''); htm.push(''); @@ -888,12 +750,60 @@ function config_info(p){ htm.push(''+'numprocs = $pnum$'+''); htm.push(''); - for(var i=0,len=data.length; i'); - htm.push(''+data[i][0]+':'); - htm.push(''); - htm.push(''); - } + htm.push(''); + htm.push(''+data[0][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[1][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[2][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[3][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[4][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[5][0]+':'); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''+data[6][0]+':'); + htm.push(''+data[6][1]+''); + htm.push(''); + + htm.push(''); + htm.push(''+data[7][0]+':'); + htm.push(''+data[7][1]+''); + htm.push(''); + + htm.push(''); + htm.push(''+data[8][0]+':'); + htm.push(''+data[8][1]+''); + htm.push(''); + + htm.push(''); + htm.push(''+data[9][0]+':'); + htm.push(''+data[9][1]+''); + htm.push(''); + + htm.push(''); + htm.push(''+data[10][0]+':'); + htm.push(''+data[10][1]+''); + htm.push(''); htm.push(''); $('#config_div').html(htm.join('')); @@ -912,11 +822,7 @@ function host_list_table(p){ var htm=['']; if (data!='' && data!=undefined && data!=null){ if($('#leftDiv').attr('path') == "online"){ - if (data[0][3]=='python' || data[0][3]=='nodejs'){ - htm.push(''); - } else { - htm.push(''); - } + htm.push(''); for(var i=0,len=data.length; i'); @@ -929,16 +835,16 @@ function host_list_table(p){ if (data[0][3]=='python' || data[0][3]=='nodejs'){ htm.push(''); } - if(data[i][5] == "RUNNING"){ - htm.push(''); - } else if(data[i][5] == "SSHOK"){ - htm.push(''); + if(data[i][6] == "RUNNING"){ + htm.push(''); + } else if(data[i][6] == "SSHOK"){ + htm.push(''); } else { - htm.push(''); + htm.push(''); } - htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); htm.push(''); } @@ -946,28 +852,22 @@ function host_list_table(p){ } if($('#leftDiv').attr('path') == "project_admin"){ - if (data[0][3]=='python'|| data[0][3]=='nodejs'){ - htm.push(''); - } else { - htm.push(''); - } + htm.push(''); for(var i=0,len=data.length; i'); htm.push(''); htm.push(''); - if (data[0][3]=='nodejs' || data[0][3]=='python'){ - htm.push(''); - } - if(data[i][5] == "RUNNING"){ - htm.push(''); - } else if(data[i][5] == "SSHOK"){ - htm.push(''); + htm.push(''); + htm.push(''); + if(data[i][6] == "RUNNING"){ + htm.push(''); + } else if(data[i][6] == "SSHOK"){ + htm.push(''); }else{ - htm.push(''); + htm.push(''); } - htm.push(''); - htm.push(''); + htm.push(''); htm.push(''); htm.push(''); htm.push(''); @@ -986,16 +886,16 @@ function host_list_status(p){ $.getJSON('/hostlist', param, function(data){ if (data!='' && data!=undefined && data!=null){ for(var i=0,len=data.length; i'+data[i][5]+''); - } else if(data[i][5] == "SSHOK"){ - $('#status'+data[i][0].replace(/\./g,"-")).html(''+data[i][5]+''); + if(data[i][6] == "RUNNING"){ + $('#status'+data[i][0].replace(/\./g,"-")).html(''+data[i][6]+''); + } else if(data[i][6] == "SSHOK"){ + $('#status'+data[i][0].replace(/\./g,"-")).html(''+data[i][6]+''); } else { - $('#status'+data[i][0].replace(/\./g,"-")).html(''+data[i][5]+''); + $('#status'+data[i][0].replace(/\./g,"-")).html(''+data[i][6]+''); } - $('#checkTime'+data[i][0].replace(/\./g,"-")).html(data[i][8]); - $('#commitID'+data[i][0].replace(/\./g,"-")).html(data[i][6]); - $('#UpdateTime'+data[i][0].replace(/\./g,"-")).html(data[i][7]); + $('#checkTime'+data[i][0].replace(/\./g,"-")).html(data[i][7]); + $('#commitID'+data[i][0].replace(/\./g,"-")).html(data[i][8]); + $('#UpdateTime'+data[i][0].replace(/\./g,"-")).html(data[i][10]); } } @@ -1386,12 +1286,7 @@ function push_edit_project_table(p){ htm.push(''); htm.push(''); - htm.push(''); - htm.push(''); - - htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); htm.push(''); htm.push(''); @@ -1400,74 +1295,29 @@ function push_edit_project_table(p){ htm.push(''); htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - - htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); htm.push(''); htm.push(''); - htm.push(''); + htm.push(''); htm.push(''); htm.push(''); htm.push(''); - htm.push(''); + htm.push(''); htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - - if (data[7]=="yes"){ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - }else{ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - } - - if (data[8]=="yes"){ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - }else{ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - } - - if (data[10]=="yes"){ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - }else{ - htm.push(''); - htm.push(''); - htm.push(''); - htm.push(''); - } htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); htm.push(''); @@ -1552,13 +1402,85 @@ function push_edit_config_table(p){ htm.push(''); htm.push(''); - for(var i=0,len=data.length; i'); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + + if (data[6][1]=="yes"){ + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + }else{ + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + } + + if (data[7][1]=="yes"){ + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + }else{ htm.push(''); - htm.push(''); - htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + } + + + if (data[8][1]=="yes"){ + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + }else{ + htm.push(''); + htm.push(''); + htm.push(''); htm.push(''); } + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); + htm.push(''); + htm.push(''); + htm.push(''); + + htm.push(''); htm.push(''); htm.push(''); @@ -1639,17 +1561,18 @@ $("#lastlog").on('click', function(){ $("body").on('click', '#update_config', function(){ if (confirm('请确认配置信息')) { - var project = $('#ipt_project').val() - var config1 = $('#config0').val() - var config2 = $('#config1').val() - var config3 = $('#config2').val() - var config4 = $('#config3').val() - var config5 = $('#config4').val() - var config6 = $('#config5').val() - var config7 = $('#config6').val() - var config8 = $('#config7').val() - var config9 = $('#config8').val() - var config10 = $('#config9').val() + var project = $('#ipt_project').val() + var make = $('#make').val() + var supervisor = $('#supervisor').val() + var config = $('#config').val() + var remarks = $('#remarks').val() + var startcmd = $('#startcmd').val() + var packfile = $('#packfile').val() + var istag = $('#istag').val() + var checkport = $('#checkport').val() + var checkhttp = $('#checkhttp').val() + var httpurl = $('#httpurl').val() + var httpcode = $('#httpcode').val() if(!project ){ alert('project null'); @@ -1657,17 +1580,18 @@ $("body").on('click', '#update_config', function(){ } var param = { - project: project, - config1: config1, - config2: config2, - config3: config3, - config4: config4, - config5: config5, - config6: config6, - config7: config7, - config8: config8, - config9: config9, - config10: config10, + project : project, + make : make, + supervisor : supervisor, + config : config, + remarks : remarks, + startcmd : startcmd, + packfile : packfile, + istag : istag, + checkport : checkport, + checkhttp : checkhttp, + httpurl : httpurl, + httpcode : httpcode } $.post('/update_config', param, function(data){
hostnameippnumstatuscheckTimecommitIDUpdateTimestop
hostnameipstatuscheckTimecommitIDUpdateTimestop
hostnameippnumstatuscheckTimecommitIDUpdateTimestop
'+data[i][4]+''+'stop'+'
hostnameippnumstatusENVDeployConfsavedelete
hostnameipstatusENVDeployConfsavedelete
hostnameippnumENVstatusDeployConfsavedelete
'+''+''+''+''+''+''+''+data[i][5]+''+''+''+data[i][5]+''+''+''+''+''+''+''+data[i][6]+''+''+''+data[i][6]+''+''+''+data[i][5]+''+''+''+data[i][6]+''+''+''+'
Business line:'+''+'
project:'+''+''+''+'
git:'+''+'
branch:'+''+'project:'+''+'
type:'+''+''+''+'
port:'+''+''+''+'
make:'+''+'
tag:'+''+'
tag:'+''+'
isnginx:'+''+'
isnginx:'+''+'
httpCheck:'+''+'
httpCheck:'+''+'
checkURL:'+''+'git:'+''+'
statusCode:'+''+'branch:'+''+'
'+'numprocs = $pnum$'+'
'+data[0][0]+':
'+data[1][0]+':
'+data[2][0]+':
'+data[3][0]+':
'+data[4][0]+':
'+data[5][0]+':
'+data[6][0]+':'+''+'
'+data[6][0]+':'+''+'
'+data[7][0]+':'+''+'
'+data[i][0]+':'+data[7][0]+':'+''+'
'+data[8][0]+':'+''+'
'+data[8][0]+':'+''+'
'+data[9][0]+':'+''+'
'+data[10][0]+':'+''+'