def run(self): action = self.task['action'] if 'stop' == action: result = killProcess(self.task['processId']) if result['code'] == 0: settings.CACHE_TASK_IDS.remove(self.taskid) r = execReportThread(self.taskid, 2, '执行成功') r.start() else: r = execReportThread(self.taskid, 3, result['msg']) r.start() if 'start' == action: appname = self.task['name'] appversion = self.task['appVersion'] confversion = self.task['confVersion'] ok = True # 判断程序版本是否存在,不存在则下载,并把version文件移到新文件夹 if not os.path.exists(settings.APP_ROOT + appname + '/app/' + appversion + '/' + appname + '.jar'): try: os.makedirs(settings.APP_ROOT + appname + '/app/' + appversion) except Exception as e: log.error(str(e)) if not dowload('jar', appname, appversion): ok = False r = execReportThread(self.taskid, 3, 'Jar包下载失败') r.start() # 判断配置文件是否存在,存在则下载并覆盖,不存在则下载 if not os.path.exists(settings.APP_ROOT + appname + '/conf/' + confversion + '/' + appname + '.properties'): try: os.makedirs(settings.APP_ROOT + appname + '/conf/' + confversion) except Exception as e: log.error(str(e)) if not dowload('conf', appname, confversion): ok = False r = execReportThread(self.taskid, 3, '配置文件下载失败') r.start() if ok: try: oldappversion = osutil.getAppVersion(appname) if oldappversion != appversion: shutil.move(settings.APP_ROOT + appname + '/app/' + oldappversion + '/version', settings.APP_ROOT + appname + '/app/' + appversion + '/version') oldconfversion = osutil.getConfVersion(appname) if oldconfversion != confversion: shutil.move(settings.APP_ROOT + appname + '/conf/' + oldconfversion + '/version', settings.APP_ROOT + appname + '/conf/' + confversion + '/version') except Exception as e: ok = False log.error(str(e)) r = execReportThread(self.taskid, 3, '切换版本出错') r.start() if ok: t = startJavaThread(appname) t.start() settings.CACHE_TASK_IDS.remove(self.taskid) r = execReportThread(self.taskid, 2, '执行成功') r.start()
def run(self): _env = os.environ.copy() _env["APPNAME"] = self.appname appversion = osutil.getAppVersion(self.appname) confversion = osutil.getConfVersion(self.appname) apppath = settings.APP_ROOT + self.appname + '/app/' + appversion + '/' + self.appname + '.jar' confpath = settings.APP_ROOT + self.appname + '/conf/' + confversion + '/' try: jvm = settings.APP_OPTS[self.appname] except KeyError as e: jvm = '' cmd = 'java ' + ' -Dnutz.boot.configure.properties.dir=' + confpath + ' ' + jvm + ' -jar ' + apppath log.info(cmd) subprocess.call(cmd,close_fds=True,shell=True,env=_env)