From 4b8d1acdf42aab139ccdb0f7fe7f123f23c4a54f Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 21 Jul 2022 15:46:36 +0200 Subject: [PATCH 1/3] allow providing list of services not to start Signed-off-by: jkoberg --- changelog/unreleased/exclude-services-option.md | 7 +++++++ ocis-pkg/config/config.go | 3 ++- ocis/pkg/runtime/service/service.go | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/exclude-services-option.md diff --git a/changelog/unreleased/exclude-services-option.md b/changelog/unreleased/exclude-services-option.md new file mode 100644 index 000000000..45df11ebe --- /dev/null +++ b/changelog/unreleased/exclude-services-option.md @@ -0,0 +1,7 @@ +Enhancement: Allow providing list of services NOT to start + +Until now if one wanted to use a custom version of a service, one +needed to provide `OCIS_RUN_SERVICES` which is a list of all services to start. +Now one can provide `OCIS_EXCLUDE_RUN_SERVICES` which is a list of only services not to start + +https://github.com/owncloud/ocis/pull/4254 diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 2aa26107c..0abdc1f5a 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -49,7 +49,8 @@ type Mode int type Runtime struct { Port string `yaml:"port" env:"OCIS_RUNTIME_PORT"` Host string `yaml:"host" env:"OCIS_RUNTIME_HOST"` - Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES"` + Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a space seperated list of service names. Will start only the listed services."` + Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a space seperated list of service names. Will start all services except of the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` } // Config combines all available configuration parts. diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 2cc5a3e3d..a0bed4d48 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -248,12 +248,24 @@ func (s *Service) generateRunSet(cfg *ociscfg.Config) { return } + disabled := make(map[string]bool) + if cfg.Runtime.Disabled != "" { + e := strings.Split(strings.ReplaceAll(cfg.Runtime.Disabled, " ", ""), ",") + for _, s := range e { + disabled[s] = true + } + } + for name := range s.ServicesRegistry { - runset = append(runset, name) + if !disabled[name] { + runset = append(runset, name) + } } for name := range s.Delayed { - runset = append(runset, name) + if !disabled[name] { + runset = append(runset, name) + } } } From db363b680041a9dbd60c9d7854c24d2fe26bb014 Mon Sep 17 00:00:00 2001 From: kobergj Date: Thu, 21 Jul 2022 15:54:56 +0200 Subject: [PATCH 2/3] Update ocis-pkg/config/config.go Co-authored-by: Phil Davis --- ocis-pkg/config/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 0abdc1f5a..6156624a1 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -49,8 +49,8 @@ type Mode int type Runtime struct { Port string `yaml:"port" env:"OCIS_RUNTIME_PORT"` Host string `yaml:"host" env:"OCIS_RUNTIME_HOST"` - Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a space seperated list of service names. Will start only the listed services."` - Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a space seperated list of service names. Will start all services except of the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` + Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start only the listed services."` + Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start all services except for the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` } // Config combines all available configuration parts. From f64ea7dc1b14a055367dc7d5d5e7d343902c54e3 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 21 Jul 2022 16:18:00 +0200 Subject: [PATCH 3/3] make runset a map Signed-off-by: jkoberg --- ocis-pkg/config/config.go | 4 ++-- ocis/pkg/runtime/service/service.go | 30 +++++++++++++---------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 6156624a1..342652cab 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -49,8 +49,8 @@ type Mode int type Runtime struct { Port string `yaml:"port" env:"OCIS_RUNTIME_PORT"` Host string `yaml:"host" env:"OCIS_RUNTIME_HOST"` - Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start only the listed services."` - Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a space separated list of service names. Will start all services except for the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` + Extensions string `yaml:"services" env:"OCIS_RUN_EXTENSIONS;OCIS_RUN_SERVICES" desc:"Expects a comma separated list of service names. Will start only the listed services."` + Disabled string `yaml:"disabled_services" env:"OCIS_EXCLUDE_RUN_SERVICES" desc:"Expects a comma separated list of service names. Will start all services except of the ones listed. Has no effect when OCIS_RUN_SERVICES is set."` } // Config combines all available configuration parts. diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index a0bed4d48..ed9fa60e0 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -54,7 +54,7 @@ import ( var ( // runset keeps track of which extensions to start supervised. - runset []string + runset map[string]struct{} ) type serviceFuncMap map[string]func(*ociscfg.Config) suture.Service @@ -227,7 +227,7 @@ func Start(o ...Option) error { // scheduleServiceTokens adds service tokens to the service supervisor. func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) { - for _, name := range runset { + for name := range runset { if _, ok := funcSet[name]; !ok { continue } @@ -240,31 +240,27 @@ func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) { // generateRunSet interprets the cfg.Runtime.Extensions config option to cherry-pick which services to start using // the runtime. func (s *Service) generateRunSet(cfg *ociscfg.Config) { + runset = make(map[string]struct{}) if cfg.Runtime.Extensions != "" { e := strings.Split(strings.ReplaceAll(cfg.Runtime.Extensions, " ", ""), ",") - for i := range e { - runset = append(runset, e[i]) + for _, name := range e { + runset[name] = struct{}{} } return } - disabled := make(map[string]bool) - if cfg.Runtime.Disabled != "" { - e := strings.Split(strings.ReplaceAll(cfg.Runtime.Disabled, " ", ""), ",") - for _, s := range e { - disabled[s] = true - } - } - for name := range s.ServicesRegistry { - if !disabled[name] { - runset = append(runset, name) - } + runset[name] = struct{}{} } for name := range s.Delayed { - if !disabled[name] { - runset = append(runset, name) + runset[name] = struct{}{} + } + + if cfg.Runtime.Disabled != "" { + e := strings.Split(strings.ReplaceAll(cfg.Runtime.Disabled, " ", ""), ",") + for _, name := range e { + delete(runset, name) } } }