From eb54030ecdf8cd6aaaf4c35c7be62a9f5116b1f3 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:25:20 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20supervisor=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD=20(#2634)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/systemctl/systemctl.go | 15 +++++---------- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/utils/systemctl/systemctl.go b/backend/utils/systemctl/systemctl.go index ee981880f..0f7ef19db 100644 --- a/backend/utils/systemctl/systemctl.go +++ b/backend/utils/systemctl/systemctl.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pkg/errors" "os/exec" + "strings" ) func RunSystemCtl(args ...string) (string, error) { @@ -31,20 +32,14 @@ func IsEnable(serviceName string) (bool, error) { return out == "enabled\n", nil } -// IsExist checks if a service exists. func IsExist(serviceName string) (bool, error) { - cmd := exec.Command("systemctl", "is-enabled", serviceName) - output, err := cmd.CombinedOutput() + out, err := RunSystemCtl("is-enabled", serviceName) if err != nil { - // If the command fails, check if the output indicates that the service does not exist. - if string(output) == fmt.Sprintf("Failed to get unit file state for %s.service: No such file or directory\n", serviceName) { - // Return false if the service does not exist. - return false, nil + if strings.Contains(out, "disabled") { + return true, nil } - // Return an error if the command fails. - return false, fmt.Errorf("failed to run command: %w", err) + return false, nil } - // Return true if the service exists. return true, nil } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f2192d86b..1faf98f01 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1886,6 +1886,7 @@ const message = { STARTING: 'Starting', FATAL: 'Failed to start', BACKOFF: 'Start exception', + ERROR: 'Error', statusCode: 'Status code', manage: 'Management', }, diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index f1833e8b2..703a3793b 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1781,6 +1781,7 @@ const message = { STARTING: '啟動中', FATAL: '啟動失敗', BACKOFF: '啟動異常', + ERROR: '錯誤', statusCode: '狀態碼', manage: '管理', }, diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 029a805db..d5b26b91f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1781,6 +1781,7 @@ const message = { STARTING: '启动中', FATAL: '启动失败', BACKOFF: '启动异常', + ERROR: '错误', statusCode: '状态码', manage: '管理', },