mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: supervisor 优化状态判断 (#2634)
This commit is contained in:
parent
88120aa988
commit
eb54030ecd
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunSystemCtl(args ...string) (string, error) {
|
func RunSystemCtl(args ...string) (string, error) {
|
||||||
@ -31,20 +32,14 @@ func IsEnable(serviceName string) (bool, error) {
|
|||||||
return out == "enabled\n", nil
|
return out == "enabled\n", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExist checks if a service exists.
|
|
||||||
func IsExist(serviceName string) (bool, error) {
|
func IsExist(serviceName string) (bool, error) {
|
||||||
cmd := exec.Command("systemctl", "is-enabled", serviceName)
|
out, err := RunSystemCtl("is-enabled", serviceName)
|
||||||
output, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the command fails, check if the output indicates that the service does not exist.
|
if strings.Contains(out, "disabled") {
|
||||||
if string(output) == fmt.Sprintf("Failed to get unit file state for %s.service: No such file or directory\n", serviceName) {
|
return true, nil
|
||||||
// Return false if the service does not exist.
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
// Return an error if the command fails.
|
return false, nil
|
||||||
return false, fmt.Errorf("failed to run command: %w", err)
|
|
||||||
}
|
}
|
||||||
// Return true if the service exists.
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1886,6 +1886,7 @@ const message = {
|
|||||||
STARTING: 'Starting',
|
STARTING: 'Starting',
|
||||||
FATAL: 'Failed to start',
|
FATAL: 'Failed to start',
|
||||||
BACKOFF: 'Start exception',
|
BACKOFF: 'Start exception',
|
||||||
|
ERROR: 'Error',
|
||||||
statusCode: 'Status code',
|
statusCode: 'Status code',
|
||||||
manage: 'Management',
|
manage: 'Management',
|
||||||
},
|
},
|
||||||
|
@ -1781,6 +1781,7 @@ const message = {
|
|||||||
STARTING: '啟動中',
|
STARTING: '啟動中',
|
||||||
FATAL: '啟動失敗',
|
FATAL: '啟動失敗',
|
||||||
BACKOFF: '啟動異常',
|
BACKOFF: '啟動異常',
|
||||||
|
ERROR: '錯誤',
|
||||||
statusCode: '狀態碼',
|
statusCode: '狀態碼',
|
||||||
manage: '管理',
|
manage: '管理',
|
||||||
},
|
},
|
||||||
|
@ -1781,6 +1781,7 @@ const message = {
|
|||||||
STARTING: '启动中',
|
STARTING: '启动中',
|
||||||
FATAL: '启动失败',
|
FATAL: '启动失败',
|
||||||
BACKOFF: '启动异常',
|
BACKOFF: '启动异常',
|
||||||
|
ERROR: '错误',
|
||||||
statusCode: '状态码',
|
statusCode: '状态码',
|
||||||
manage: '管理',
|
manage: '管理',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user