@name 修改JDK版本 @author lkq<2021-08-27> @param get.tomcat_start tomcat启动脚本路径 @param get.jdk_path JDK路径 @return string
(self, get)
| 242 | return False |
| 243 | |
| 244 | def replace_jdk_version(self, get): |
| 245 | ''' |
| 246 | @name 修改JDK版本 |
| 247 | @author lkq<2021-08-27> |
| 248 | @param get.tomcat_start tomcat启动脚本路径 |
| 249 | @param get.jdk_path JDK路径 |
| 250 | @return string |
| 251 | ''' |
| 252 | jdk_path = get.jdk_path.strip() |
| 253 | jdk_path2 = jdk_path.split('/') |
| 254 | if jdk_path2[-1] == 'java': |
| 255 | if jdk_path2[-3] == 'jre': |
| 256 | jdk_path2 = '/'.join(jdk_path2[:-3]) |
| 257 | if jdk_path2[-2] == 'bin': |
| 258 | jdk_path2 = '/'.join(jdk_path2[:-2]) |
| 259 | else: |
| 260 | jdk_path2 = '/'.join(jdk_path2[:-1]) |
| 261 | # 检查jdk是否可用 |
| 262 | jdk_path = jdk_path2 |
| 263 | jdk_data = self.check_jdk(jdk_path) |
| 264 | if not jdk_data: return public.returnMsg(False, '请输入正确的JDK路径,例如:/www/server/jdk1.8/bin/java') |
| 265 | if jdk_data: |
| 266 | if not os.path.exists(jdk_data): return public.returnMsg(False, 'JDK目录不存在!') |
| 267 | if not jdk_data: return public.returnMsg(False, '当前输入的JDK不可用!') |
| 268 | tomcat_start = get.tomcat_start.strip() |
| 269 | if not os.path.exists(tomcat_start): return public.returnMsg(False, 'tomcat启动脚本不存在!') |
| 270 | tomcat_start_file = public.ReadFile(tomcat_start) |
| 271 | if isinstance(tomcat_start_file, str): |
| 272 | # 正则匹配到jdk_path |
| 273 | jdk_path_re = re.findall('^JAVA_HOME=(.*)$', tomcat_start_file, re.M) |
| 274 | if jdk_path_re: |
| 275 | tomcat_start_file = tomcat_start_file.replace(jdk_path_re[0], jdk_path) |
| 276 | public.WriteFile(tomcat_start, tomcat_start_file) |
| 277 | # 重启服务 |
| 278 | public.ExecShell('bash %s stop' % (tomcat_start)) |
| 279 | public.ExecShell('bash %s start' % (tomcat_start)) |
| 280 | return public.returnMsg(True, '修改成功!') |
| 281 | return public.returnMsg(False, '修改失败!') |
| 282 | |
| 283 | def get_tomcat_version(self, get): |
| 284 | ''' |