diff --git a/accounts/pkg/flagset/flagset.go b/accounts/pkg/flagset/flagset.go index 9542d75c3..733ed3d25 100644 --- a/accounts/pkg/flagset/flagset.go +++ b/accounts/pkg/flagset/flagset.go @@ -28,6 +28,10 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go index d3bc91a00..fc3ae3cfb 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -30,6 +30,10 @@ 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", + }, } } diff --git a/graph-explorer/pkg/flagset/flagset.go b/graph-explorer/pkg/flagset/flagset.go index baa5723f2..c17f9049e 100644 --- a/graph-explorer/pkg/flagset/flagset.go +++ b/graph-explorer/pkg/flagset/flagset.go @@ -27,6 +27,10 @@ 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", + }, } } diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index 8b96cbf37..a2caad8cd 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -34,6 +34,10 @@ 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", + }, } } diff --git a/idp/pkg/flagset/flagset.go b/idp/pkg/flagset/flagset.go index 9b4c15437..56a8efe52 100644 --- a/idp/pkg/flagset/flagset.go +++ b/idp/pkg/flagset/flagset.go @@ -30,6 +30,10 @@ 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", + }, } } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index b6a652e60..5c392471a 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -70,8 +70,9 @@ type Mode int // Runtime configures the oCIS runtime when running in supervised mode. type Runtime struct { - Port string - Host string + Port string + Host string + Extensions string } // Config combines all available configuration parts. diff --git a/ocis/pkg/flagset/flagset.go b/ocis/pkg/flagset/flagset.go index 1267d6475..e9dd54534 100644 --- a/ocis/pkg/flagset/flagset.go +++ b/ocis/pkg/flagset/flagset.go @@ -162,5 +162,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"OCIS_GRPC_ADDR"}, Destination: &cfg.GRPC.Addr, }, + &cli.StringFlag{ + Name: "extensions", + Aliases: []string{"e"}, + Usage: "Run specific extensions during supervised mode", + EnvVars: []string{"OCIS_RUN_EXTENSIONS"}, + Destination: &cfg.Runtime.Extensions, + }, } } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 268d7473f..f3ab45120 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -22,6 +22,7 @@ import ( graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/command" graph "github.com/owncloud/ocis/graph/pkg/command" idp "github.com/owncloud/ocis/idp/pkg/command" + "github.com/owncloud/ocis/ocis-pkg/config" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/log" ocs "github.com/owncloud/ocis/ocs/pkg/command" @@ -37,6 +38,11 @@ import ( "github.com/thejerf/suture/v4" ) +var ( + // runset keeps track of which extensions to start supervised. + runset []string +) + // Service represents a RPC service. type Service struct { Supervisor *suture.Supervisor @@ -180,7 +186,18 @@ func Start(o ...Option) error { } }() - for name := range s.ServicesRegistry { + // prepare runset + 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)))) } @@ -198,7 +215,12 @@ func Start(o ...Option) error { time.Sleep(1 * time.Second) // add services with delayed execution. - for name := range s.Delayed { + 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)))) } @@ -206,6 +228,24 @@ func Start(o ...Option) error { return http.Serve(l, nil) } +func (s *Service) generateRunSet(cfg *config.Config) { + if cfg.Runtime.Extensions != "" { + e := strings.Split(strings.Replace(cfg.Runtime.Extensions, " ", "", -1), ",") + for i := range e { + runset = append(runset, e[i]) + } + return + } + + for name := range s.ServicesRegistry { + runset = append(runset, name) + } + + for name := range s.Delayed { + runset = append(runset, name) + } +} + // Start indicates the Service Controller to start a new supervised service as an OS thread. func (s *Service) Start(name string, reply *int) error { // RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go index a5e69d7fc..e3ee4e4c2 100644 --- a/ocs/pkg/flagset/flagset.go +++ b/ocs/pkg/flagset/flagset.go @@ -179,6 +179,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"OCS_STORAGE_USERS_DRIVER", "STORAGE_USERS_DRIVER"}, Destination: &cfg.StorageUsersDriver, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/onlyoffice/pkg/flagset/flagset.go b/onlyoffice/pkg/flagset/flagset.go index d8a59bd5a..fe630095b 100644 --- a/onlyoffice/pkg/flagset/flagset.go +++ b/onlyoffice/pkg/flagset/flagset.go @@ -34,6 +34,10 @@ 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", + }, } } diff --git a/proxy/pkg/flagset/flagset.go b/proxy/pkg/flagset/flagset.go index 87ad472d4..b2cbd818e 100644 --- a/proxy/pkg/flagset/flagset.go +++ b/proxy/pkg/flagset/flagset.go @@ -30,6 +30,10 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/settings/pkg/flagset/flagset.go b/settings/pkg/flagset/flagset.go index 8aa7a5aab..b5d0f64b2 100644 --- a/settings/pkg/flagset/flagset.go +++ b/settings/pkg/flagset/flagset.go @@ -27,6 +27,10 @@ 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", + }, } } diff --git a/storage/pkg/flagset/authbasic.go b/storage/pkg/flagset/authbasic.go index 4f5ae182b..dbf19c67d 100644 --- a/storage/pkg/flagset/authbasic.go +++ b/storage/pkg/flagset/authbasic.go @@ -76,6 +76,7 @@ func AuthBasicWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, LDAPWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/authbearer.go b/storage/pkg/flagset/authbearer.go index d35e3bd2e..863807c8e 100644 --- a/storage/pkg/flagset/authbearer.go +++ b/storage/pkg/flagset/authbearer.go @@ -102,6 +102,7 @@ func AuthBearerWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/drivereos.go b/storage/pkg/flagset/drivereos.go index 416a433ee..da130a628 100644 --- a/storage/pkg/flagset/drivereos.go +++ b/storage/pkg/flagset/drivereos.go @@ -131,5 +131,9 @@ func DriverEOSWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_DRIVER_EOS_GATEWAYSVC"}, Destination: &cfg.Reva.Storages.EOS.GatewaySVC, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/driverlocal.go b/storage/pkg/flagset/driverlocal.go index 256d117e9..86f2e1e78 100644 --- a/storage/pkg/flagset/driverlocal.go +++ b/storage/pkg/flagset/driverlocal.go @@ -16,5 +16,9 @@ func DriverLocalWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_DRIVER_LOCAL_ROOT"}, Destination: &cfg.Reva.Storages.Local.Root, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/driverocis.go b/storage/pkg/flagset/driverocis.go index 75f80caaa..90cee48e0 100644 --- a/storage/pkg/flagset/driverocis.go +++ b/storage/pkg/flagset/driverocis.go @@ -37,5 +37,9 @@ func DriverOCISWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_DRIVER_OCIS_SERVICE_USER_UUID"}, Destination: &cfg.Reva.Storages.OCIS.ServiceUserUUID, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/driverowncloud.go b/storage/pkg/flagset/driverowncloud.go index 65dfd183e..faf532c7d 100644 --- a/storage/pkg/flagset/driverowncloud.go +++ b/storage/pkg/flagset/driverowncloud.go @@ -58,5 +58,9 @@ func DriverOwnCloudWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_DRIVER_OWNCLOUD_LAYOUT"}, Destination: &cfg.Reva.Storages.OwnCloud.UserLayout, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/drivers3ng.go b/storage/pkg/flagset/drivers3ng.go index b755ac28e..6384b2c6b 100644 --- a/storage/pkg/flagset/drivers3ng.go +++ b/storage/pkg/flagset/drivers3ng.go @@ -65,5 +65,9 @@ func DriverS3NGWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_DRIVER_S3NG_BUCKET"}, Destination: &cfg.Reva.Storages.S3NG.Bucket, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/frontend.go b/storage/pkg/flagset/frontend.go index e872cfdf2..cfd6fd620 100644 --- a/storage/pkg/flagset/frontend.go +++ b/storage/pkg/flagset/frontend.go @@ -183,6 +183,7 @@ func FrontendWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/gateway.go b/storage/pkg/flagset/gateway.go index af603478f..241d31bd7 100644 --- a/storage/pkg/flagset/gateway.go +++ b/storage/pkg/flagset/gateway.go @@ -264,6 +264,7 @@ func GatewayWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/groups.go b/storage/pkg/flagset/groups.go index cde281020..71cc96666 100644 --- a/storage/pkg/flagset/groups.go +++ b/storage/pkg/flagset/groups.go @@ -79,6 +79,7 @@ func GroupsWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, LDAPWithConfig(cfg)...) flags = append(flags, RestWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/ldap.go b/storage/pkg/flagset/ldap.go index b5f069a45..2a2cacf28 100644 --- a/storage/pkg/flagset/ldap.go +++ b/storage/pkg/flagset/ldap.go @@ -208,5 +208,9 @@ func LDAPWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_LDAP_GROUP_SCHEMA_GID_NUMBER"}, Destination: &cfg.Reva.LDAP.GroupSchema.GIDNumber, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/rest.go b/storage/pkg/flagset/rest.go index 34980637e..977eca8b6 100644 --- a/storage/pkg/flagset/rest.go +++ b/storage/pkg/flagset/rest.go @@ -72,5 +72,9 @@ func RestWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_REST_TARGET_API"}, Destination: &cfg.Reva.UserGroupRest.TargetAPI, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/root.go b/storage/pkg/flagset/root.go index c2aaa3023..af2357bd6 100644 --- a/storage/pkg/flagset/root.go +++ b/storage/pkg/flagset/root.go @@ -33,5 +33,9 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/runtime_extensions.go b/storage/pkg/flagset/runtime_extensions.go new file mode 100644 index 000000000..7805d9624 --- /dev/null +++ b/storage/pkg/flagset/runtime_extensions.go @@ -0,0 +1,16 @@ +package flagset + +import ( + "github.com/micro/cli/v2" + "github.com/owncloud/ocis/storage/pkg/config" +) + +// RuntimeConfig applies common debug config cfg to the flagset +func RuntimeConfig(cfg *config.Config) []cli.Flag { + return []cli.Flag{ + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, + } +} diff --git a/storage/pkg/flagset/sharing.go b/storage/pkg/flagset/sharing.go index b9a1d989e..da1754e08 100644 --- a/storage/pkg/flagset/sharing.go +++ b/storage/pkg/flagset/sharing.go @@ -98,6 +98,7 @@ func SharingWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, SharingSQLWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/sharingsql.go b/storage/pkg/flagset/sharingsql.go index e4770b4a9..938d24f4f 100644 --- a/storage/pkg/flagset/sharingsql.go +++ b/storage/pkg/flagset/sharingsql.go @@ -44,5 +44,9 @@ func SharingSQLWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_SHARING_USER_SQL_NAME"}, Destination: &cfg.Reva.Sharing.UserSQLName, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } } diff --git a/storage/pkg/flagset/storagehome.go b/storage/pkg/flagset/storagehome.go index 153679586..c090951ab 100644 --- a/storage/pkg/flagset/storagehome.go +++ b/storage/pkg/flagset/storagehome.go @@ -157,6 +157,7 @@ func StorageHomeWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, DriverOwnCloudWithConfig(cfg)...) flags = append(flags, DriverOCISWithConfig(cfg)...) flags = append(flags, DriverS3NGWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/storagemetadata.go b/storage/pkg/flagset/storagemetadata.go index fe28e0024..21edf4e2b 100644 --- a/storage/pkg/flagset/storagemetadata.go +++ b/storage/pkg/flagset/storagemetadata.go @@ -106,6 +106,8 @@ func StorageMetadata(cfg *config.Config) []cli.Flag { f = append(f, DriverOwnCloudWithConfig(cfg)...) f = append(f, DriverOCISWithConfig(cfg)...) f = append(f, DriverS3NGWithConfig(cfg)...) + f = append(f, RuntimeConfig(cfg)...) + return f } diff --git a/storage/pkg/flagset/storagepubliclink.go b/storage/pkg/flagset/storagepubliclink.go index eefc636a3..05eff876b 100644 --- a/storage/pkg/flagset/storagepubliclink.go +++ b/storage/pkg/flagset/storagepubliclink.go @@ -53,6 +53,7 @@ func StoragePublicLink(cfg *config.Config) []cli.Flag { flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/storageusers.go b/storage/pkg/flagset/storageusers.go index eaf18cd18..a7618373c 100644 --- a/storage/pkg/flagset/storageusers.go +++ b/storage/pkg/flagset/storageusers.go @@ -147,6 +147,7 @@ func StorageUsersWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, DriverOwnCloudWithConfig(cfg)...) flags = append(flags, DriverOCISWithConfig(cfg)...) flags = append(flags, DriverS3NGWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/users.go b/storage/pkg/flagset/users.go index 091cefb12..3a335f2a1 100644 --- a/storage/pkg/flagset/users.go +++ b/storage/pkg/flagset/users.go @@ -79,6 +79,7 @@ func UsersWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, LDAPWithConfig(cfg)...) flags = append(flags, RestWithConfig(cfg)...) + flags = append(flags, RuntimeConfig(cfg)...) return flags } diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go index c1c68b8aa..b020149aa 100644 --- a/thumbnails/pkg/flagset/flagset.go +++ b/thumbnails/pkg/flagset/flagset.go @@ -169,6 +169,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, Destination: &cfg.Thumbnail.WebdavNamespace, }, + &cli.StringFlag{ + Name: "extensions", + Usage: "Run specific extensions during supervised mode", + }, } }