(self, get)
| 3712 | return json_response(status = True, msg = "更新任务已开始") |
| 3713 | |
| 3714 | def force_stop(self, get): |
| 3715 | try: |
| 3716 | project_name = get.project_name.strip() |
| 3717 | project_data = self.get_project_find(project_name) |
| 3718 | except: |
| 3719 | return json_response(status = False, msg = "参数错误") |
| 3720 | |
| 3721 | if not project_data: |
| 3722 | return json_response(False, "未找到项目") |
| 3723 | |
| 3724 | project_config = project_data["project_config"] |
| 3725 | pid_file = "{}/keep/{}.pid".format(self._java_project_path, project_name) |
| 3726 | pid_data = public.readFile(pid_file) |
| 3727 | if isinstance(pid_data, str) and pid_data != "0": |
| 3728 | try: |
| 3729 | p = psutil.Process(int(pid_data)) |
| 3730 | p.kill() |
| 3731 | except: |
| 3732 | pass |
| 3733 | |
| 3734 | service_list = [] |
| 3735 | rep_service = re.compile(r"^spring_%s_\S{8}$" % public.prevent_re_key(project_name), re.M) |
| 3736 | for i in os.scandir("/usr/lib/systemd/system"): |
| 3737 | if i.is_file() and rep_service.match(i.name): |
| 3738 | service_list.append(i.name) |
| 3739 | |
| 3740 | now_name = self._get_systemd_server_name(project_config) |
| 3741 | if now_name in service_list: |
| 3742 | service_list.remove(now_name) |
| 3743 | |
| 3744 | for i in service_list: |
| 3745 | public.ExecShell("systemctl stop {}".format(i)) |
| 3746 | os.remove("/usr/lib/systemd/system/{}".format(i)) |
| 3747 | |
| 3748 | public.ExecShell("systemctl daemon-reload") |
| 3749 | upstream_file = "/www/server/panel/vhost/nginx/java_{}_upstream.conf".format(project_name) |
| 3750 | if os.path.isfile(upstream_file): # 说明新旧同时存在 则删除旧的 |
| 3751 | upstream_data = public.readFile(upstream_file) |
| 3752 | if isinstance(upstream_data, str): |
| 3753 | old_upstream_data = re.search(r"server 127\.0\.0\.1:(?P<port>\d+);", upstream_data) |
| 3754 | if old_upstream_data: |
| 3755 | old_port = old_upstream_data.group("port") |
| 3756 | ng_file = "/www/server/panel/vhost/nginx/java_{}.conf".format(project_name) |
| 3757 | ng_data = public.readFile(ng_file) |
| 3758 | if not isinstance(ng_data, str): |
| 3759 | return "Nginx配置文件读取错误,无法取消轮询,使用新实例" |
| 3760 | new_config = ng_data.replace("{}_backend".format(project_name), "127.0.0.1:{}".format(old_port)) |
| 3761 | |
| 3762 | public.writeFile(ng_file, new_config) |
| 3763 | res = public.checkWebConfig() |
| 3764 | if res is not True: |
| 3765 | public.writeFile(ng_file, ng_data) |
| 3766 | else: |
| 3767 | os.remove(upstream_file) |
| 3768 | public.serviceReload() |
| 3769 | |
| 3770 | return json_response(status = True, msg = "强制停止成功") |
| 3771 |
nothing calls this directly
no test coverage detected