mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-10 19:50:53 +08:00
fix: fix issue with agent cpu usage error (#8792)
Refs https://github.com/1Panel-dev/1Panel/issues/8742
This commit is contained in:
parent
28ab4e2527
commit
433a911ef6
9 changed files with 28 additions and 18 deletions
|
|
@ -2,6 +2,8 @@ package cmd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -89,7 +91,17 @@ func (c *CommandHelper) RunWithStdoutBashCf(command string, arg ...interface{})
|
|||
}
|
||||
|
||||
func (c *CommandHelper) run(name string, arg ...string) (string, error) {
|
||||
cmd := exec.Command(name, arg...)
|
||||
var cmd *exec.Cmd
|
||||
var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
|
||||
if c.timeout != 0 {
|
||||
ctx, cancel = context.WithTimeout(context.Background(), c.timeout)
|
||||
defer cancel()
|
||||
cmd = exec.CommandContext(ctx, name, arg...)
|
||||
} else {
|
||||
cmd = exec.Command(name, arg...)
|
||||
}
|
||||
|
||||
customWriter := &CustomWriter{taskItem: c.taskItem}
|
||||
var stdout, stderr bytes.Buffer
|
||||
|
|
@ -122,26 +134,16 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
|
|||
}
|
||||
|
||||
if c.timeout != 0 {
|
||||
if err := cmd.Start(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- cmd.Wait()
|
||||
err := cmd.Run()
|
||||
if c.taskItem != nil {
|
||||
customWriter.Flush()
|
||||
}
|
||||
}()
|
||||
after := time.After(c.timeout)
|
||||
select {
|
||||
case <-after:
|
||||
_ = cmd.Process.Kill()
|
||||
if ctx != nil && errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
||||
return "", buserr.New("ErrCmdTimeout")
|
||||
case err := <-done:
|
||||
}
|
||||
if err != nil {
|
||||
return handleErr(stdout, stderr, err)
|
||||
}
|
||||
}
|
||||
return stdout.String(), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2821,6 +2821,7 @@ const message = {
|
|||
statusCode: 'Status code',
|
||||
manage: 'Management',
|
||||
autoRestart: 'Auto Restart',
|
||||
EXITED: 'Exited',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2687,6 +2687,7 @@ const message = {
|
|||
statusCode: 'ステータスコード',
|
||||
manage: '管理',
|
||||
autoRestart: '自動再起動',
|
||||
EXITED: '終了しました',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2643,6 +2643,7 @@ const message = {
|
|||
statusCode: '상태 코드',
|
||||
manage: '관리',
|
||||
autoRestart: '자동 재시작',
|
||||
EXITED: '종료됨',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2747,6 +2747,7 @@ const message = {
|
|||
statusCode: 'Kod status',
|
||||
manage: 'Pengurusan',
|
||||
autoRestart: 'Auto Restart',
|
||||
EXITED: 'Telah keluar',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2747,6 +2747,7 @@ const message = {
|
|||
statusCode: 'Código de status',
|
||||
manage: 'Gerenciamento',
|
||||
autoRestart: 'Reinicialização Automática',
|
||||
EXITED: 'Saiu',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2740,6 +2740,7 @@ const message = {
|
|||
statusCode: 'Код статуса',
|
||||
manage: 'Управление',
|
||||
autoRestart: 'Автоматический перезапуск',
|
||||
EXITED: 'Вышел',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2611,6 +2611,7 @@ const message = {
|
|||
statusCode: '狀態碼',
|
||||
manage: '管理',
|
||||
autoRestart: '自動重啟',
|
||||
EXITED: '已退出',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
|
|
@ -2602,6 +2602,7 @@ const message = {
|
|||
statusCode: '状态码',
|
||||
manage: '管理',
|
||||
autoRestart: '自动重启',
|
||||
EXITED: '已退出',
|
||||
},
|
||||
},
|
||||
xpack: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue