diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go index fc3ae3cfb..29ef1069a 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -30,10 +30,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"GLAUTH_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -295,5 +291,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"}, Destination: &cfg.Fallback.UseGraphAPI, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/graph-explorer/pkg/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go index c17f9049e..54ca8b446 100644 --- a/graph-explorer/pkg/flagset/flagset.go +++ b/graph-explorer/pkg/flagset/flagset.go @@ -27,10 +27,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"GRAPH_EXPLORER_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -158,5 +154,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL"}, Destination: &cfg.GraphExplorer.GraphURL, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index a2caad8cd..495eb7b6b 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -34,10 +34,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"GRAPH_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -220,5 +216,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, Destination: &cfg.WebdavNamespace, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/idp/pkg/flagset/flagset.go b/idp/pkg/flagset/flagset.go index 56a8efe52..aa41ee52a 100644 --- a/idp/pkg/flagset/flagset.go +++ b/idp/pkg/flagset/flagset.go @@ -30,10 +30,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"IDP_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -421,7 +417,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"}, Destination: &cfg.IDP.RefreshTokenDurationSeconds, Value: flags.OverrideDefaultUint64(cfg.IDP.RefreshTokenDurationSeconds, 60*60*24*365*3), // 1 year - + }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", }, } } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index f3ab45120..7db99b159 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -186,21 +186,11 @@ func Start(o ...Option) error { } }() - // prepare runset + // prepare the set of services to run s.generateRunSet(s.cfg) - for _, name := range runset { - - // skip delayed services for now - if _, ok := s.Delayed[name]; ok { - continue - } - - // we do this so each service has its own copy. In a perfect world a config object should NOT be edited by - // the callers because this might trigger behavioral changes up the tree. - swap := deepcopy.Copy(s.cfg) - s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config)))) - } + // schedule services that we are sure don't have interdependencies. + scheduleServiceTokens(s, s.ServicesRegistry) // there are reasons not to do this, but we have race conditions ourselves. Until we resolve them, mind the following disclaimer: // Calling ServeBackground will CORRECTLY start the supervisor running in a new goroutine. It is risky to directly run @@ -212,22 +202,27 @@ func Start(o ...Option) error { // trap will block on halt channel for interruptions. go trap(s, halt) - time.Sleep(1 * time.Second) - // add services with delayed execution. - for _, name := range runset { - // this time around only run delayed jobs - if _, ok := s.Delayed[name]; !ok { - continue - } - - swap := deepcopy.Copy(s.cfg) - s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.Delayed[name](swap.(*ociscfg.Config)))) - } + time.Sleep(1 * time.Second) + scheduleServiceTokens(s, s.Delayed) return http.Serve(l, nil) } +// scheduleServiceTokens adds service tokens to the service supervisor. +func scheduleServiceTokens(s *Service, funcSet map[string]func(*ociscfg.Config) suture.Service) { + for _, name := range runset { + if _, ok := funcSet[name]; !ok { + continue + } + + swap := deepcopy.Copy(s.cfg) + s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(funcSet[name](swap.(*ociscfg.Config)))) + } +} + +// generateRunSet interprets the cfg.Runtime.Extensions config option to cherry-pick which services to start using +// the runtime. func (s *Service) generateRunSet(cfg *config.Config) { if cfg.Runtime.Extensions != "" { e := strings.Split(strings.Replace(cfg.Runtime.Extensions, " ", "", -1), ",") diff --git a/onlyoffice/pkg/flagset/flagset.go b/onlyoffice/pkg/flagset/flagset.go index fe630095b..6517b8dc0 100644 --- a/onlyoffice/pkg/flagset/flagset.go +++ b/onlyoffice/pkg/flagset/flagset.go @@ -34,10 +34,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"ONLYOFFICE_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -158,5 +154,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"ONLYOFFICE_ASSET_PATH"}, Destination: &cfg.Asset.Path, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/settings/pkg/flagset/flagset.go b/settings/pkg/flagset/flagset.go index b5d0f64b2..8a253abeb 100644 --- a/settings/pkg/flagset/flagset.go +++ b/settings/pkg/flagset/flagset.go @@ -27,10 +27,6 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"SETTINGS_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, - &cli.StringFlag{ - Name: "extensions", - Usage: "Run specific extensions during supervised mode", - }, } } @@ -187,6 +183,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"SETTINGS_JWT_SECRET", "OCIS_JWT_SECRET"}, Destination: &cfg.TokenManager.JWTSecret, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/store/pkg/flagset/flagset.go b/store/pkg/flagset/flagset.go index f87f08efc..578cdf1cc 100644 --- a/store/pkg/flagset/flagset.go +++ b/store/pkg/flagset/flagset.go @@ -140,6 +140,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORE_DATA_PATH"}, Destination: &cfg.Datapath, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/web/pkg/flagset/flagset.go b/web/pkg/flagset/flagset.go index 717663f98..10f6c79f7 100644 --- a/web/pkg/flagset/flagset.go +++ b/web/pkg/flagset/flagset.go @@ -223,5 +223,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"WEB_OIDC_SCOPE"}, Destination: &cfg.Web.Config.OpenIDConnect.Scope, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } } diff --git a/webdav/pkg/flagset/flagset.go b/webdav/pkg/flagset/flagset.go index 0d8a29b95..f77bc528a 100644 --- a/webdav/pkg/flagset/flagset.go +++ b/webdav/pkg/flagset/flagset.go @@ -142,19 +142,23 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { Destination: &cfg.HTTP.Root, }, &cli.StringFlag{ - Name: "ocis-public-url", - Value: flags.OverrideDefaultString(cfg.OcisPublicURL, "https://127.0.0.1:9200"), - Usage: "The domain under which oCIS is reachable", - EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"}, + Name: "ocis-public-url", + Value: flags.OverrideDefaultString(cfg.OcisPublicURL, "https://127.0.0.1:9200"), + Usage: "The domain under which oCIS is reachable", + EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"}, Destination: &cfg.OcisPublicURL, }, &cli.StringFlag{ - Name: "webdav-namespace", - Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"), - Usage: "Namespace prefix for the /webdav endpoint", - EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Name: "webdav-namespace", + Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"), + Usage: "Namespace prefix for the /webdav endpoint", + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, Destination: &cfg.WebdavNamespace, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode. This flag is set by the runtime", + }, } }