Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow providing list of services not to start #4254

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/exclude-services-option.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion ocis-pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
Expand Down
20 changes: 14 additions & 6 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -240,20 +240,28 @@ 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
}

for name := range s.ServicesRegistry {
runset = append(runset, name)
runset[name] = struct{}{}
}

for name := range s.Delayed {
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)
}
}
}

Expand Down