From 381233a8a55f10eea827fdde46574c35b273d557 Mon Sep 17 00:00:00 2001
From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com>
Date: Tue, 8 Aug 2023 17:00:12 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=20Supervisor=20?=
=?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=20(#1876)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
backend/app/service/host_tool.go | 15 ++++++++++-----
backend/utils/cmd/cmd.go | 5 +++++
backend/utils/systemctl/systemctl.go | 9 ---------
.../host/tool/supervisor/config/basic/index.vue | 2 +-
.../views/host/tool/supervisor/config/index.vue | 2 +-
5 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/backend/app/service/host_tool.go b/backend/app/service/host_tool.go
index 2dca140c2..5955231f4 100644
--- a/backend/app/service/host_tool.go
+++ b/backend/app/service/host_tool.go
@@ -43,11 +43,17 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host
res.Type = req.Type
switch req.Type {
case constant.Supervisord:
- exist, _ := systemctl.IsExist(constant.Supervisord)
supervisorConfig := &response.Supervisor{}
- if !exist {
- exist, _ = systemctl.IsExist(constant.Supervisor)
- if !exist {
+ if !cmd.Which(constant.Supervisord) {
+ supervisorConfig.IsExist = false
+ res.Config = supervisorConfig
+ return res, nil
+ }
+ supervisorConfig.IsExist = true
+ serviceExist, _ := systemctl.IsExist(constant.Supervisord)
+ if !serviceExist {
+ serviceExist, _ = systemctl.IsExist(constant.Supervisor)
+ if !serviceExist {
supervisorConfig.IsExist = false
res.Config = supervisorConfig
return res, nil
@@ -57,7 +63,6 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host
} else {
supervisorConfig.ServiceName = constant.Supervisord
}
- supervisorConfig.IsExist = true
serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName))
if serviceNameSet.ID != 0 || serviceNameSet.Value != "" {
diff --git a/backend/utils/cmd/cmd.go b/backend/utils/cmd/cmd.go
index ff65a8e50..74804d269 100644
--- a/backend/utils/cmd/cmd.go
+++ b/backend/utils/cmd/cmd.go
@@ -168,3 +168,8 @@ func SudoHandleCmd() string {
}
return ""
}
+
+func Which(name string) bool {
+ _, err := exec.LookPath(name)
+ return err == nil
+}
diff --git a/backend/utils/systemctl/systemctl.go b/backend/utils/systemctl/systemctl.go
index 27ff4be6d..402fbf7a0 100644
--- a/backend/utils/systemctl/systemctl.go
+++ b/backend/utils/systemctl/systemctl.go
@@ -46,15 +46,6 @@ func Restart(serviceName string) error {
out, err := RunSystemCtl("restart", serviceName)
return handlerErr(out, err)
}
-func Start(serviceName string) error {
- out, err := RunSystemCtl("start", serviceName)
- return handlerErr(out, err)
-}
-
-func Stop(serviceName string) error {
- out, err := RunSystemCtl("stop", serviceName)
- return handlerErr(out, err)
-}
func Operate(operate, serviceName string) error {
out, err := RunSystemCtl(operate, serviceName)
diff --git a/frontend/src/views/host/tool/supervisor/config/basic/index.vue b/frontend/src/views/host/tool/supervisor/config/basic/index.vue
index 54fb5c1da..53e01cdf5 100644
--- a/frontend/src/views/host/tool/supervisor/config/basic/index.vue
+++ b/frontend/src/views/host/tool/supervisor/config/basic/index.vue
@@ -65,7 +65,7 @@ const submit = async (formEl: FormInstance | undefined) => {
serviceName: data.value.serviceName,
})
.then(() => {
- MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
+ MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
})
.finally(() => {
loading.value = false;
diff --git a/frontend/src/views/host/tool/supervisor/config/index.vue b/frontend/src/views/host/tool/supervisor/config/index.vue
index 64900c935..116d95c4b 100644
--- a/frontend/src/views/host/tool/supervisor/config/index.vue
+++ b/frontend/src/views/host/tool/supervisor/config/index.vue
@@ -8,7 +8,7 @@
{{ $t('website.log') }}
- {{ $t('website.basic') }}
+ {{ $t('commons.button.init') }}