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

Refs https://github.com/1Panel-dev/1Panel/issues/2051
pull/2068/head
zhengkunwang 1 year ago committed by GitHub
parent ca0368c931
commit a3c07dd3d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save