diff --git a/.gitignore b/.gitignore index 4af6f7b6b..10af3845c 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ install.sh quick_start.sh cmd/server/web/.DS_Store cmd/server/.DS_Store +cmd/server/fileList.txt diff --git a/backend/app/dto/request/host_tool.go b/backend/app/dto/request/host_tool.go index e9863e8df..aef43182d 100644 --- a/backend/app/dto/request/host_tool.go +++ b/backend/app/dto/request/host_tool.go @@ -11,7 +11,8 @@ type HostToolCreate struct { } type SupervisorConfig struct { - ConfigPath string `json:"configPath"` + ConfigPath string `json:"configPath"` + ServiceName string `json:"serviceName"` } type HostToolLogReq struct { diff --git a/backend/app/dto/response/host_tool.go b/backend/app/dto/response/host_tool.go index 76d38716f..1b9ca012f 100644 --- a/backend/app/dto/response/host_tool.go +++ b/backend/app/dto/response/host_tool.go @@ -6,15 +6,16 @@ type HostToolRes struct { } type Supervisor struct { - ConfigPath string `json:"configPath"` - IncludeDir string `json:"includeDir"` - LogPath string `json:"logPath"` - IsExist bool `json:"isExist"` - Init bool `json:"init"` - Msg string `json:"msg"` - Version string `json:"version"` - Status string `json:"status"` - CtlExist bool `json:"ctlExist"` + ConfigPath string `json:"configPath"` + IncludeDir string `json:"includeDir"` + LogPath string `json:"logPath"` + IsExist bool `json:"isExist"` + Init bool `json:"init"` + Msg string `json:"msg"` + Version string `json:"version"` + Status string `json:"status"` + CtlExist bool `json:"ctlExist"` + ServiceName string `json:"serviceName"` } type HostToolConfig struct { diff --git a/backend/app/service/host_tool.go b/backend/app/service/host_tool.go index 9e0e3b583..191bbbfcd 100644 --- a/backend/app/service/host_tool.go +++ b/backend/app/service/host_tool.go @@ -43,29 +43,33 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host res.Type = req.Type switch req.Type { case constant.Supervisord: - exist, err := systemctl.IsExist(constant.Supervisord) - if err != nil { - return nil, err - } + exist, _ := systemctl.IsExist(constant.Supervisord) supervisorConfig := &response.Supervisor{} if !exist { - supervisorConfig.IsExist = false - return res, nil + exist, _ = systemctl.IsExist(constant.Supervisor) + if !exist { + supervisorConfig.IsExist = false + res.Config = supervisorConfig + return res, nil + } else { + supervisorConfig.ServiceName = constant.Supervisor + } + } else { + supervisorConfig.ServiceName = constant.Supervisord } supervisorConfig.IsExist = true + serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName)) + if serviceNameSet.ID != 0 || serviceNameSet.Value != "" { + supervisorConfig.ServiceName = serviceNameSet.Value + } + versionRes, _ := cmd.Exec("supervisord -v") supervisorConfig.Version = strings.TrimSuffix(versionRes, "\n") _, ctlRrr := exec.LookPath("supervisorctl") supervisorConfig.CtlExist = ctlRrr == nil - active, err := systemctl.IsActive(constant.Supervisord) - if err != nil { - supervisorConfig.Status = "unhealthy" - supervisorConfig.Msg = err.Error() - res.Config = supervisorConfig - return res, nil - } + active, _ := systemctl.IsActive(supervisorConfig.ServiceName) if active { supervisorConfig.Status = "running" } else { @@ -77,13 +81,14 @@ func (h *HostToolService) GetToolStatus(req request.HostToolReq) (*response.Host supervisorConfig.ConfigPath = pathSet.Value res.Config = supervisorConfig return res, nil + } else { + supervisorConfig.Init = true } - supervisorConfig.Init = true - servicePath := "/usr/lib/systemd/system/supervisord.service" + servicePath := "/usr/lib/systemd/system/supervisor.service" fileOp := files.NewFileOp() if !fileOp.Stat(servicePath) { - servicePath = "/lib/systemd/system/supervisord.service" + servicePath = "/usr/lib/systemd/system/supervisord.service" } if fileOp.Stat(servicePath) { startCmd, _ := ini_conf.GetIniValue(servicePath, "Service", "ExecStart") @@ -161,9 +166,12 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error { if err = settingRepo.Create(constant.SupervisorConfigPath, req.ConfigPath); err != nil { return err } + if err = settingRepo.Create(constant.SupervisorServiceName, req.ServiceName); err != nil { + return err + } go func() { - if err = systemctl.Restart(constant.Supervisord); err != nil { - global.LOG.Errorf("[init] restart supervisord failed err %s", err.Error()) + if err = systemctl.Restart(req.ServiceName); err != nil { + global.LOG.Errorf("[init] restart %s failed err %s", req.ServiceName, err.Error()) } }() } @@ -171,19 +179,31 @@ func (h *HostToolService) CreateToolConfig(req request.HostToolCreate) error { } func (h *HostToolService) OperateTool(req request.HostToolReq) error { - return systemctl.Operate(req.Operate, req.Type) + serviceName := req.Type + if req.Type == constant.Supervisord { + serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName)) + if serviceNameSet.ID != 0 || serviceNameSet.Value != "" { + serviceName = serviceNameSet.Value + } + } + return systemctl.Operate(req.Operate, serviceName) } func (h *HostToolService) OperateToolConfig(req request.HostToolConfig) (*response.HostToolConfig, error) { fileOp := files.NewFileOp() res := &response.HostToolConfig{} configPath := "" + serviceName := "supervisord" switch req.Type { case constant.Supervisord: pathSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorConfigPath)) if pathSet.ID != 0 || pathSet.Value != "" { configPath = pathSet.Value } + serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName)) + if serviceNameSet.ID != 0 || serviceNameSet.Value != "" { + serviceName = serviceNameSet.Value + } } switch req.Operate { case "get": @@ -208,7 +228,7 @@ func (h *HostToolService) OperateToolConfig(req request.HostToolConfig) (*respon if err = fileOp.WriteFile(configPath, strings.NewReader(req.Content), fileInfo.Mode()); err != nil { return nil, err } - if err = systemctl.Restart(req.Type); err != nil { + if err = systemctl.Restart(serviceName); err != nil { _ = fileOp.WriteFile(configPath, bytes.NewReader(oldContent), fileInfo.Mode()) return nil, err } diff --git a/backend/constant/host_tool.go b/backend/constant/host_tool.go index bfaff46c8..60f483b02 100644 --- a/backend/constant/host_tool.go +++ b/backend/constant/host_tool.go @@ -1,6 +1,8 @@ package constant const ( - Supervisord = "supervisord" - SupervisorConfigPath = "SupervisorConfigPath" + Supervisord = "supervisord" + Supervisor = "supervisor" + SupervisorConfigPath = "SupervisorConfigPath" + SupervisorServiceName = "SupervisorServiceName" ) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index b21f95181..441f83719 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -15377,6 +15377,9 @@ const docTemplate = `{ "configPath": { "type": "string" }, + "serviceName": { + "type": "string" + }, "type": { "type": "string" } diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 011aaccd7..f0f846eca 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -15370,6 +15370,9 @@ "configPath": { "type": "string" }, + "serviceName": { + "type": "string" + }, "type": { "type": "string" } diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 6589381e9..1d9c4d884 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -2652,6 +2652,8 @@ definitions: properties: configPath: type: string + serviceName: + type: string type: type: string required: diff --git a/frontend/src/api/interface/host-tool.ts b/frontend/src/api/interface/host-tool.ts index cb60deda6..3a5d00b9d 100644 --- a/frontend/src/api/interface/host-tool.ts +++ b/frontend/src/api/interface/host-tool.ts @@ -14,6 +14,7 @@ export namespace HostTool { version: string; status: string; ctlExist: boolean; + serviceName: string; } export interface SupersivorConfig { @@ -30,6 +31,7 @@ export namespace HostTool { export interface SupersivorInit { type: string; configPath: string; + serviceName: string; } export interface SupersivorProcess { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index edffb08f2..90b922dc1 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1668,6 +1668,8 @@ const message = { 'Because it is not compatible with the original configuration, initializing Supervisor will modify the files parameter of the configuration file, causing all existing processes to stop, please confirm the risk in advance. The modified process configuration folder is in <1Panel installation directory>/1panel/tools/supervisord/supervisor.d', operatorHelper: 'Operation {1} will be performed on {0}, continue? ', uptime: 'running time', + notStartWarn: 'Supervisor is not started, please start it first', + serviceName: 'Service name', }, }, }; diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 7806fb767..c507bda5b 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1585,6 +1585,8 @@ const message = { '由於無法兼容原有配置,初始化 Supervisor 會修改配置文件的 files 參數,導致已有的進程全部停止,請提前確認風險。修改後的進程配置文件夾在 <1Panel安裝目錄>/1panel/tools/supervisord/supervisor.d 中', operatorHelper: '將對 {0} 進行 {1} 操作,是否繼續? ', uptime: '運行時長', + notStartWarn: 'Supervisor 未啟動,請先啟動', + serviceName: '服務名稱', }, }, }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 66a938e85..496f28584 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1587,6 +1587,8 @@ const message = { '由于无法兼容原有配置,初始化 Supervisor 会修改配置文件的 files 参数,导致已有的进程全部停止,请提前确认风险。修改后的进程配置文件夹在 <1Panel安装目录>/1panel/tools/supervisord/supervisor.d 中', operatorHelper: '将对 {0} 进行 {1} 操作,是否继续?', uptime: '运行时长', + notStartWarn: '当前未开启 Supervisor ,请先启动', + serviceName: '服务名称', }, }, }; diff --git a/frontend/src/views/host/tool/supervisor/index.vue b/frontend/src/views/host/tool/supervisor/index.vue index d83dc2973..ff9a364dc 100644 --- a/frontend/src/views/host/tool/supervisor/index.vue +++ b/frontend/src/views/host/tool/supervisor/index.vue @@ -2,7 +2,7 @@