| 564 | return public.returnMsg(True, '修改成功') |
| 565 | |
| 566 | def change_duli_tomcat_jdk(self, project_name, jdk_path): |
| 567 | project_info = self.get_project_find(project_name) |
| 568 | if not project_info: |
| 569 | return public.returnMsg(False, "项目不存在") |
| 570 | project_conf = project_info['project_config'] |
| 571 | if project_conf["java_type"] != "duli": |
| 572 | return public.returnMsg(False, "项目类型错误") |
| 573 | |
| 574 | if not os.path.exists(jdk_path): |
| 575 | return public.returnMsg(False, "指定的jdk路径不存在") |
| 576 | if jdk_path.endswith("/bin/java"): |
| 577 | jdk_path = jdk_path[:-9] |
| 578 | |
| 579 | _, error = public.ExecShell("{}/bin/java -version".format(jdk_path)) # 信息在标准错误 |
| 580 | if not (error.find("version") != -1 and error.find("Runtime") != -1): |
| 581 | return public.returnMsg(False, "指定的jdk不可用") |
| 582 | |
| 583 | tomcat_path = "/www/server/bt_tomcat_web/{}".format(project_name) |
| 584 | if not os.path.isdir(tomcat_path): |
| 585 | return public.returnMsg(False, '没有安装Tomcat!') |
| 586 | |
| 587 | deemon_sh_path = "{}/bin/daemon.sh".format(tomcat_path) |
| 588 | if not os.path.isfile(deemon_sh_path): |
| 589 | return public.returnMsg(False, 'Tomcat启动文件丢失!') |
| 590 | |
| 591 | deemon_sh_data = public.readFile(deemon_sh_path) |
| 592 | if not isinstance(deemon_sh_data, str): |
| 593 | return public.returnMsg(False, 'Tomcat启动文件读取失败!') |
| 594 | |
| 595 | # deemon_sh |
| 596 | rep_deemon_sh = re.compile(r"^JAVA_HOME=(?P<path>.*)\n", re.M) |
| 597 | re_res_deemon_sh = rep_deemon_sh.search(deemon_sh_data) |
| 598 | if not re_res_deemon_sh: |
| 599 | return public.returnMsg(False, 'Tomcat启动文件解析失败!') |
| 600 | |
| 601 | jsvc_make_path = None |
| 602 | for i in os.listdir(tomcat_path + "/bin"): |
| 603 | tmp_dir = "{}/bin/{}".format(tomcat_path, i) |
| 604 | if i.startswith("commons-daemon") and os.path.isdir(tmp_dir): |
| 605 | make_path = tmp_dir + "/unix" |
| 606 | if os.path.isdir(make_path): |
| 607 | jsvc_make_path = make_path |
| 608 | break |
| 609 | |
| 610 | if jsvc_make_path is None: |
| 611 | return public.returnMsg(False, 'Jsvc文件丢失!') |
| 612 | |
| 613 | # 重装jsvc |
| 614 | if os.path.isfile(tomcat_path + "/bin/jsvc"): |
| 615 | os.remove(tomcat_path + "/bin/jsvc") |
| 616 | |
| 617 | if os.path.isfile(jsvc_make_path + "/jsvc"): |
| 618 | os.remove(jsvc_make_path + "/jsvc") |
| 619 | |
| 620 | shell_str = r''' |
| 621 | cd {} |
| 622 | make clean |
| 623 | ./configure --with-java={} |