mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 12:39:01 +08:00
feat: supervisor 优化状态判断 (#2634)
This commit is contained in:
parent
88120aa988
commit
eb54030ecd
@ -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
|
||||
}
|
||||
|
||||
|
@ -1886,6 +1886,7 @@ const message = {
|
||||
STARTING: 'Starting',
|
||||
FATAL: 'Failed to start',
|
||||
BACKOFF: 'Start exception',
|
||||
ERROR: 'Error',
|
||||
statusCode: 'Status code',
|
||||
manage: 'Management',
|
||||
},
|
||||
|
@ -1781,6 +1781,7 @@ const message = {
|
||||
STARTING: '啟動中',
|
||||
FATAL: '啟動失敗',
|
||||
BACKOFF: '啟動異常',
|
||||
ERROR: '錯誤',
|
||||
statusCode: '狀態碼',
|
||||
manage: '管理',
|
||||
},
|
||||
|
@ -1781,6 +1781,7 @@ const message = {
|
||||
STARTING: '启动中',
|
||||
FATAL: '启动失败',
|
||||
BACKOFF: '启动异常',
|
||||
ERROR: '错误',
|
||||
statusCode: '状态码',
|
||||
manage: '管理',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user