From a3c07dd3d31a115e219794b441d0f7ccca6b769e Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:16:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=89=93=E5=BC=80?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E5=AE=88=E6=8A=A4=E9=A1=B5=E9=9D=A2=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=20(#2057)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/2051 --- backend/app/service/host_tool.go | 36 +++++++++---------- .../src/views/host/tool/supervisor/index.vue | 8 +++-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/backend/app/service/host_tool.go b/backend/app/service/host_tool.go index e68d7696e..d3b6e48ed 100644 --- a/backend/app/service/host_tool.go +++ b/backend/app/service/host_tool.go @@ -378,25 +378,25 @@ func (h *HostToolService) OperateSupervisorProcess(req request.SupervisorProcess } func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error) { - var datas []response.ProcessStatus - statuLines, err := cmd.Exec("supervisorctl status") - if err != nil { - return datas, fmt.Errorf("exec `supervisorctl status` failed, err: %v", statuLines) + var res []response.ProcessStatus + statusLines, _ := cmd.Exec("supervisorctl status") + if len(statusLines) == 0 { + return res, nil } - lines := strings.Split(string(statuLines), "\n") + lines := strings.Split(statusLines, "\n") for _, line := range lines { fields := strings.Fields(line) if len(fields) > 1 { - datas = append(datas, response.ProcessStatus{Name: fields[0]}) + res = append(res, response.ProcessStatus{Name: fields[0]}) } } var wg sync.WaitGroup - wg.Add(len(datas)) - for i := 0; i < len(datas); i++ { + wg.Add(len(res)) + for i := 0; i < len(res); i++ { go func(index int) { for t := 0; t < 3; t++ { - status, err := cmd.ExecWithTimeOut(fmt.Sprintf("supervisorctl status %s", datas[index].Name), 2*time.Second) + status, err := cmd.ExecWithTimeOut(fmt.Sprintf("supervisorctl status %s", res[index].Name), 2*time.Second) if err != nil { time.Sleep(2 * time.Second) continue @@ -406,25 +406,25 @@ func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error) time.Sleep(2 * time.Second) continue } - datas[index].Name = fields[0] - datas[index].Status = fields[1] + res[index].Name = fields[0] + res[index].Status = fields[1] if fields[1] != "RUNNING" { - datas[index].Msg = strings.Join(fields[2:], " ") + res[index].Msg = strings.Join(fields[2:], " ") break } - datas[index].PID = strings.TrimSuffix(fields[3], ",") - datas[index].Uptime = fields[5] + res[index].PID = strings.TrimSuffix(fields[3], ",") + res[index].Uptime = fields[5] break } - if len(datas[index].Status) == 0 { - datas[index].Status = "FATAL" - datas[index].Msg = "Timeout for getting process status" + if len(res[index].Status) == 0 { + res[index].Status = "FATAL" + res[index].Msg = "Timeout for getting process status" } wg.Done() }(i) } wg.Wait() - return datas, nil + return res, nil } func (h *HostToolService) GetSupervisorProcessConfig() ([]response.SupervisorProcessConfig, error) { diff --git a/frontend/src/views/host/tool/supervisor/index.vue b/frontend/src/views/host/tool/supervisor/index.vue index 65996c978..9d88e3a85 100644 --- a/frontend/src/views/host/tool/supervisor/index.vue +++ b/frontend/src/views/host/tool/supervisor/index.vue @@ -184,6 +184,7 @@ const setting = () => { const getStatus = (status: any) => { supervisorStatus.value = status; + search(); }; const showStopped = computed((): boolean => { @@ -211,6 +212,9 @@ const openCreate = () => { }; const search = async () => { + if (!supervisorStatus.value.isExist) { + return; + } loading.value = true; loadStatus(); try { @@ -231,9 +235,7 @@ const loadStatus = async () => { process.status.push(item); } } - if (process.status.length !== 0) { - process.hasLoad = true; - } + process.hasLoad = true; } }) .catch(() => {