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:
parent
627e1e3755
commit
4d5993c6ab
@ -378,25 +378,25 @@ func (h *HostToolService) OperateSupervisorProcess(req request.SupervisorProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error) {
|
func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error) {
|
||||||
var datas []response.ProcessStatus
|
var res []response.ProcessStatus
|
||||||
statuLines, err := cmd.Exec("supervisorctl status")
|
statusLines, _ := cmd.Exec("supervisorctl status")
|
||||||
if err != nil {
|
if len(statusLines) == 0 {
|
||||||
return datas, fmt.Errorf("exec `supervisorctl status` failed, err: %v", statuLines)
|
return res, nil
|
||||||
}
|
}
|
||||||
lines := strings.Split(string(statuLines), "\n")
|
lines := strings.Split(statusLines, "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) > 1 {
|
if len(fields) > 1 {
|
||||||
datas = append(datas, response.ProcessStatus{Name: fields[0]})
|
res = append(res, response.ProcessStatus{Name: fields[0]})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(datas))
|
wg.Add(len(res))
|
||||||
for i := 0; i < len(datas); i++ {
|
for i := 0; i < len(res); i++ {
|
||||||
go func(index int) {
|
go func(index int) {
|
||||||
for t := 0; t < 3; t++ {
|
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 {
|
if err != nil {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
continue
|
continue
|
||||||
@ -406,25 +406,25 @@ func (h *HostToolService) LoadProcessStatus() ([]response.ProcessStatus, error)
|
|||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
datas[index].Name = fields[0]
|
res[index].Name = fields[0]
|
||||||
datas[index].Status = fields[1]
|
res[index].Status = fields[1]
|
||||||
if fields[1] != "RUNNING" {
|
if fields[1] != "RUNNING" {
|
||||||
datas[index].Msg = strings.Join(fields[2:], " ")
|
res[index].Msg = strings.Join(fields[2:], " ")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
datas[index].PID = strings.TrimSuffix(fields[3], ",")
|
res[index].PID = strings.TrimSuffix(fields[3], ",")
|
||||||
datas[index].Uptime = fields[5]
|
res[index].Uptime = fields[5]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(datas[index].Status) == 0 {
|
if len(res[index].Status) == 0 {
|
||||||
datas[index].Status = "FATAL"
|
res[index].Status = "FATAL"
|
||||||
datas[index].Msg = "Timeout for getting process status"
|
res[index].Msg = "Timeout for getting process status"
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return datas, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HostToolService) GetSupervisorProcessConfig() ([]response.SupervisorProcessConfig, error) {
|
func (h *HostToolService) GetSupervisorProcessConfig() ([]response.SupervisorProcessConfig, error) {
|
||||||
|
@ -184,6 +184,7 @@ const setting = () => {
|
|||||||
|
|
||||||
const getStatus = (status: any) => {
|
const getStatus = (status: any) => {
|
||||||
supervisorStatus.value = status;
|
supervisorStatus.value = status;
|
||||||
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showStopped = computed((): boolean => {
|
const showStopped = computed((): boolean => {
|
||||||
@ -211,6 +212,9 @@ const openCreate = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const search = async () => {
|
const search = async () => {
|
||||||
|
if (!supervisorStatus.value.isExist) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
loadStatus();
|
loadStatus();
|
||||||
try {
|
try {
|
||||||
@ -231,10 +235,8 @@ const loadStatus = async () => {
|
|||||||
process.status.push(item);
|
process.status.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (process.status.length !== 0) {
|
|
||||||
process.hasLoad = true;
|
process.hasLoad = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
for (const process of data.value) {
|
for (const process of data.value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user