(req request.HostToolTypeReq)
| 43 | } |
| 44 | |
| 45 | func (h *HostToolService) GetToolStatus(req request.HostToolTypeReq) (*response.HostToolRes, error) { |
| 46 | res := &response.HostToolRes{} |
| 47 | res.Type = req.Type |
| 48 | switch req.Type { |
| 49 | case constant.Supervisord: |
| 50 | supervisorConfig := &response.Supervisor{} |
| 51 | if !cmd.Which(constant.Supervisord) { |
| 52 | supervisorConfig.IsExist = false |
| 53 | res.Config = supervisorConfig |
| 54 | return res, nil |
| 55 | } |
| 56 | supervisorConfig.IsExist = true |
| 57 | serviceExist, _ := controller.CheckExist(constant.Supervisord) |
| 58 | if !serviceExist { |
| 59 | serviceExist, _ = controller.CheckExist(constant.Supervisor) |
| 60 | if !serviceExist { |
| 61 | supervisorConfig.IsExist = false |
| 62 | res.Config = supervisorConfig |
| 63 | return res, nil |
| 64 | } else { |
| 65 | supervisorConfig.ServiceName = constant.Supervisor |
| 66 | } |
| 67 | } else { |
| 68 | supervisorConfig.ServiceName = constant.Supervisord |
| 69 | } |
| 70 | |
| 71 | serviceNameSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorServiceName)) |
| 72 | if serviceNameSet.ID != 0 || serviceNameSet.Value != "" { |
| 73 | supervisorConfig.ServiceName = serviceNameSet.Value |
| 74 | } |
| 75 | |
| 76 | versionRes, _ := cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout("supervisord", "-v") |
| 77 | supervisorConfig.Version = strings.TrimSuffix(versionRes, "\n") |
| 78 | _, ctlRrr := exec.LookPath("supervisorctl") |
| 79 | supervisorConfig.CtlExist = ctlRrr == nil |
| 80 | |
| 81 | active, _ := controller.CheckActive(supervisorConfig.ServiceName) |
| 82 | if active { |
| 83 | supervisorConfig.Status = "running" |
| 84 | } else { |
| 85 | supervisorConfig.Status = "stopped" |
| 86 | } |
| 87 | |
| 88 | pathSet, _ := settingRepo.Get(settingRepo.WithByKey(constant.SupervisorConfigPath)) |
| 89 | if pathSet.ID != 0 || pathSet.Value != "" { |
| 90 | supervisorConfig.ConfigPath = pathSet.Value |
| 91 | res.Config = supervisorConfig |
| 92 | return res, nil |
| 93 | } else { |
| 94 | supervisorConfig.Init = true |
| 95 | } |
| 96 | |
| 97 | servicePath := "/usr/lib/systemd/system/supervisor.service" |
| 98 | fileOp := files.NewFileOp() |
| 99 | if !fileOp.Stat(servicePath) { |
| 100 | servicePath = "/usr/lib/systemd/system/supervisord.service" |
| 101 | } |
| 102 | if fileOp.Stat(servicePath) { |
nothing calls this directly
no test coverage detected