1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决打开进程守护页面报错的问题 (#2057)

Refs https://github.com/1Panel-dev/1Panel/issues/2051
This commit is contained in:
zhengkunwang 2023-08-24 16:16:45 +08:00 committed by wanghe-fit2cloud
parent 627e1e3755
commit 4d5993c6ab
2 changed files with 23 additions and 21 deletions

View File

@ -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) {

View File

@ -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,10 +235,8 @@ const loadStatus = async () => {
process.status.push(item);
}
}
if (process.status.length !== 0) {
process.hasLoad = true;
}
}
})
.catch(() => {
for (const process of data.value) {