feat: supervisor 优化状态判断 (#2634)

This commit is contained in:
zhengkunwang 2023-10-22 22:25:20 -05:00 committed by GitHub
parent 88120aa988
commit eb54030ecd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 10 deletions

View file

@ -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
}

View file

@ -1886,6 +1886,7 @@ const message = {
STARTING: 'Starting',
FATAL: 'Failed to start',
BACKOFF: 'Start exception',
ERROR: 'Error',
statusCode: 'Status code',
manage: 'Management',
},

View file

@ -1781,6 +1781,7 @@ const message = {
STARTING: '啟動中',
FATAL: '啟動失敗',
BACKOFF: '啟動異常',
ERROR: '錯誤',
statusCode: '狀態碼',
manage: '管理',
},

View file

@ -1781,6 +1781,7 @@ const message = {
STARTING: '启动中',
FATAL: '启动失败',
BACKOFF: '启动异常',
ERROR: '错误',
statusCode: '状态码',
manage: '管理',
},