def updateServer(self, stype, version=''): # 更新服务 try: if not mw.isRestart(): return mw.returnJson(False, '请等待所有安装任务完成再执行!') if stype == 'check': version_now = config_api.config_api().getVersion() version_new_info = self.getServerInfo() if not 'version' in version_new_info: return mw.returnJson(False, '服务器数据或网络有问题!') diff = self.versionDiff(version_now, version_new_info['version']) if diff == 'new': return mw.returnJson(True, '有新版本!', version_new_info['version']) elif diff == 'test': return mw.returnJson(True, '有测试版本!', version_new_info['version']) else: return mw.returnJson(False, '已经是最新,无需更新!') if stype == 'info': version_new_info = self.getServerInfo() version_now = config_api.config_api().getVersion() if not 'version' in version_new_info: return mw.returnJson(False, '服务器数据有问题!') diff = self.versionDiff(version_now, version_new_info['version']) return mw.returnJson(True, '更新信息!', version_new_info) if stype == 'update': if version == '': return mw.returnJson(False, '缺少版本信息!') v_new_info = self.getServerInfo() if v_new_info['version'] != version: return mw.returnJson(False, '更新失败,请重试!') if not 'path' in v_new_info or v_new_info['path'] == '': return mw.returnJson(False, '下载地址不存在!') newUrl = v_new_info['path'] toPath = mw.getRootDir() + '/temp' if not os.path.exists(toPath): mw.execShell('mkdir -p ' + toPath) mw.execShell('wget -O ' + toPath + '/mw.zip ' + newUrl) mw.execShell('unzip -o ' + toPath + '/mw.zip' + ' -d ./') mw.execShell('unzip -o mw.zip -d ./') mw.execShell('rm -f mw.zip') return mw.returnJson(True, '安装更新成功,需自己重启!') return mw.returnJson(False, '已经是最新,无需更新!') except Exception as ex: print 'updateServer', ex return mw.returnJson(False, "连接服务器失败!")
def setControl(self, stype, day): filename = 'data/control.conf' if stype == '0': mw.execShell("rm -f " + filename) elif stype == '1': _day = int(day) if _day < 1: return mw.returnJson(False, "设置失败!") mw.writeFile(filename, day) elif stype == 'del': if not mw.isRestart(): return mw.returnJson(False, '请等待所有安装任务完成再执行') os.remove("data/system.db") sql = db.Sql().dbfile('system') csql = mw.readFile('data/sql/system.sql') csql_list = csql.split(';') for index in range(len(csql_list)): sql.execute(csql_list[index], ()) return mw.returnJson(True, "监控服务已关闭") else: data = {} if os.path.exists(filename): try: data['day'] = int(mw.readFile(filename)) except: data['day'] = 30 data['status'] = True else: data['day'] = 30 data['status'] = False return mw.getJson(data) return mw.returnJson(True, "设置成功!")
def restartServer(self): if not mw.isRestart(): return mw.returnJson(False, '请等待所有安装任务完成再执行!') mw.execShell("sync && init 6 &") return mw.returnJson(True, '命令发送成功!')