From 0f6e14d2f909364cb4f8974740b529fee05cecca Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:23:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Supervisor=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD=20(#1818?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + backend/app/service/host_tool.go | 25 +++++- frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../tool/supervisor/config/basic/index.vue | 79 +++++++++++++++++++ .../host/tool/supervisor/config/index.vue | 5 ++ .../src/views/host/tool/supervisor/index.vue | 46 +++++++---- .../host/tool/supervisor/status/index.vue | 51 ++++++------ .../tool/supervisor/status/init/index.vue | 12 ++- 10 files changed, 181 insertions(+), 42 deletions(-) create mode 100644 frontend/src/views/host/tool/supervisor/config/basic/index.vue diff --git a/.gitignore b/.gitignore index 10af3845c..d9ce73975 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ quick_start.sh cmd/server/web/.DS_Store cmd/server/.DS_Store cmd/server/fileList.txt +.fileList.txt diff --git a/backend/app/service/host_tool.go b/backend/app/service/host_tool.go index 191bbbfcd..aec1e7159 100644 --- a/backend/app/service/host_tool.go +++ b/backend/app/service/host_tool.go @@ -163,12 +163,29 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error { if err = cfg.SaveTo(req.ConfigPath); err != nil { return err } - if err = settingRepo.Create(constant.SupervisorConfigPath, req.ConfigPath); err != nil { - return err + + serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName)) + if serviceNameSet.ID != 0 { + if err = settingRepo.Update(constant.SupervisorServiceName, req.ServiceName); err != nil { + return err + } + } else { + if err = settingRepo.Create(constant.SupervisorServiceName, req.ServiceName); err != nil { + return err + } } - if err = settingRepo.Create(constant.SupervisorServiceName, req.ServiceName); err != nil { - return err + + configPathSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorConfigPath)) + if configPathSet.ID != 0 { + if err = settingRepo.Update(constant.SupervisorConfigPath, req.ConfigPath); err != nil { + return err + } + } else { + if err = settingRepo.Create(constant.SupervisorConfigPath, req.ConfigPath); err != nil { + return err + } } + go func() { if err = systemctl.Restart(req.ServiceName); err != nil { global.LOG.Errorf("[init] restart %s failed err %s", req.ServiceName, err.Error()) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index b6758e7cb..0faf356c6 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1672,6 +1672,8 @@ const message = { uptime: 'running time', notStartWarn: 'Supervisor is not started, please start it first', serviceName: 'Service name', + initHelper: + 'The initialization process will modify the configuration file, causing all existing processes to stop, please confirm the risk in advance', }, }, }; diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 353ca9e55..bf2024831 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1588,6 +1588,7 @@ const message = { uptime: '運行時長', notStartWarn: 'Supervisor 未啟動,請先啟動', serviceName: '服務名稱', + initHelper: '尚未初始化 Supervisor ,請先初始化', }, }, }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index bd8675df0..dd6f15b49 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1590,6 +1590,7 @@ const message = { uptime: '运行时长', notStartWarn: '当前未开启 Supervisor ,请先启动', serviceName: '服务名称', + initHelper: '尚未初始化 Supervisor ,请先初始化', }, }, }; diff --git a/frontend/src/views/host/tool/supervisor/config/basic/index.vue b/frontend/src/views/host/tool/supervisor/config/basic/index.vue new file mode 100644 index 000000000..54fb5c1da --- /dev/null +++ b/frontend/src/views/host/tool/supervisor/config/basic/index.vue @@ -0,0 +1,79 @@ + + + diff --git a/frontend/src/views/host/tool/supervisor/config/index.vue b/frontend/src/views/host/tool/supervisor/config/index.vue index f7315d354..64900c935 100644 --- a/frontend/src/views/host/tool/supervisor/config/index.vue +++ b/frontend/src/views/host/tool/supervisor/config/index.vue @@ -7,10 +7,14 @@ {{ $t('website.log') }} + + {{ $t('website.basic') }} + @@ -19,6 +23,7 @@ import { ref } from 'vue'; import Source from './source/index.vue'; import Log from './log/index.vue'; +import Basic from './basic/index.vue'; const activeName = ref('1'); diff --git a/frontend/src/views/host/tool/supervisor/index.vue b/frontend/src/views/host/tool/supervisor/index.vue index ff9a364dc..e8517e5bf 100644 --- a/frontend/src/views/host/tool/supervisor/index.vue +++ b/frontend/src/views/host/tool/supervisor/index.vue @@ -1,7 +1,7 @@ -