diff --git a/Makefile b/Makefile index 88fce5a84..9deecb82b 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,6 @@ build_items="api chaos entrance monitor mq node webcli worker eventlog" ifeq ($(origin WHAT), undefined) WHAT = all endif -ifeq ($(origin GOOS), undefined) - GOOS = darwin -endif ifeq ($(origin STATIC), undefined) STATIC = false else diff --git a/node/nodem/controller/controller_service_darwin.go b/node/nodem/controller/controller_service_darwin.go index 131f80990..bd6a08dba 100644 --- a/node/nodem/controller/controller_service_darwin.go +++ b/node/nodem/controller/controller_service_darwin.go @@ -20,12 +20,11 @@ package controller import ( "github.com/goodrain/rainbond/cmd/node/option" - "github.com/goodrain/rainbond/node/nodem/client" "github.com/goodrain/rainbond/node/nodem/service" ) //NewController At the stage you want to load the configurations of all rainbond components -func NewController(conf *option.Conf, cluster client.ClusterClient) Controller { +func NewController(conf *option.Conf, manager *ManagerService) Controller { return &testController{} } diff --git a/node/nodem/controller/controller_service_windows.go b/node/nodem/controller/controller_service_windows.go index 436a69355..38da63660 100644 --- a/node/nodem/controller/controller_service_windows.go +++ b/node/nodem/controller/controller_service_windows.go @@ -20,21 +20,20 @@ package controller import ( "github.com/goodrain/rainbond/cmd/node/option" - "github.com/goodrain/rainbond/node/nodem/client" "github.com/goodrain/rainbond/node/nodem/service" ) //NewController At the stage you want to load the configurations of all rainbond components -func NewController(conf *option.Conf, cluster client.ClusterClient) Controller { +func NewController(conf *option.Conf, manager *ManagerService) Controller { return &windowsServiceController{ conf: conf, - cluster: cluster, + manager: manager, } } type windowsServiceController struct { conf *option.Conf - cluster client.ClusterClient + manager *ManagerService } func (w *windowsServiceController) InitStart(services []*service.Service) error { diff --git a/node/nodem/controller/controller_systemd_linux.go b/node/nodem/controller/controller_systemd_linux.go index 250b7a05a..cfeb887bf 100644 --- a/node/nodem/controller/controller_systemd_linux.go +++ b/node/nodem/controller/controller_systemd_linux.go @@ -19,6 +19,7 @@ package controller import ( + "bytes" "fmt" "io/ioutil" "os" @@ -139,8 +140,8 @@ func (m *ControllerSystemd) DisableService(serviceName string) error { //WriteConfig write config func (m *ControllerSystemd) WriteConfig(s *service.Service) error { fileName := fmt.Sprintf("%s/%s.service", m.SysConfigDir, s.Name) - content := service.ToConfig(s) - content = service.InjectConfig(content, m.manager) + content := ToConfig(s) + content = m.manager.InjectConfig(content) if content == "" { err := fmt.Errorf("can not generate config for service %s", s.Name) logrus.Error(err) @@ -196,7 +197,7 @@ func (m *ControllerSystemd) InitStart(services []*service.Service) error { for _, s := range services { if s.Name == "etcd" { fileName := fmt.Sprintf("/etc/systemd/system/%s.service", s.Name) - content := service.ToConfig(s) + content := ToConfig(s) if content == "" { err := fmt.Errorf("can not generate config for service %s", s.Name) fmt.Println(err) @@ -215,13 +216,14 @@ func (m *ControllerSystemd) InitStart(services []*service.Service) error { return nil } -func ToConfig(svc *Service) string { +func ToConfig(svc *service.Service) string { if svc.Start == "" { logrus.Error("service start command is empty.") return "" } - s := service.Lines{"[Unit]"} + s := ConfigWriter{writer: bytes.NewBuffer(nil)} + s.AddTitle("[Unit]") s.Add("Description", svc.Name) for _, d := range svc.After { dpd := d @@ -257,3 +259,26 @@ func ToConfig(svc *Service) string { return s.Get() } + +type ConfigWriter struct { + writer *bytes.Buffer +} + +func (l *ConfigWriter) AddTitle(line string) { + l.writer.WriteString("\n") + l.writer.WriteString(line) +} + +func (l *ConfigWriter) Add(k, v string) { + if v == "" { + return + } + l.writer.WriteString("\n") + l.writer.WriteString(k) + l.writer.WriteString("=") + l.writer.WriteString(v) +} + +func (l *ConfigWriter) Get() string { + return l.writer.String() +} diff --git a/node/nodem/controller/manager_service.go b/node/nodem/controller/manager_service.go index fee8d97aa..e7691b6b5 100644 --- a/node/nodem/controller/manager_service.go +++ b/node/nodem/controller/manager_service.go @@ -441,11 +441,11 @@ func NewManagerService(conf *option.Conf, healthyManager healthy.Manager, cluste cancel: cancel, conf: conf, cluster: cluster, - ctr: NewController(conf, cluster), healthyManager: healthyManager, etcdcli: conf.EtcdCli, services: new([]*service.Service), allservice: new([]*service.Service), } + manager.ctr = NewController(conf, manager) return manager } diff --git a/node/nodem/service/configs.go b/node/nodem/service/configs.go index 188a58981..24c9e1a31 100644 --- a/node/nodem/service/configs.go +++ b/node/nodem/service/configs.go @@ -93,22 +93,3 @@ func loadServicesFromFile(serviceListFile string) ([]*Service, error) { } return defaultConfigs.Services, nil } - -type Lines struct { - str string -} - -func (l *Lines) AddTitle(line string) { - l.str = fmt.Sprintf("%s\n\n%s", l.str, line) -} - -func (l *Lines) Add(k, v string) { - if v == "" { - return - } - l.str = fmt.Sprintf("%s\n%s=%s", l.str, k, v) -} - -func (l *Lines) Get() string { - return l.str -}