diff --git a/idp/pkg/command/server.go b/idp/pkg/command/server.go index bd07bfbdf..57b62865d 100644 --- a/idp/pkg/command/server.go +++ b/idp/pkg/command/server.go @@ -160,8 +160,6 @@ func Server(cfg *config.Config) *cli.Command { http.Context(ctx), http.Config(cfg), http.Metrics(metrics), - http.Flags(flagset.RootWithConfig(config.New())), - http.Flags(flagset.ServerWithConfig(config.New())), ) if err != nil { diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index f8b57895f..efcf0be69 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -8,6 +8,7 @@ import ( accounts "github.com/owncloud/ocis/accounts/pkg/command" glauth "github.com/owncloud/ocis/glauth/pkg/command" idp "github.com/owncloud/ocis/idp/pkg/command" + ocs "github.com/owncloud/ocis/ocs/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" "github.com/thejerf/suture" @@ -35,8 +36,8 @@ var ( // Extensions are oCIS extension services Extensions = []string{ "glauth", // done - "idp", - "ocs", + "idp", // done + "ocs", // done "onlyoffice", "proxy", "settings", // done @@ -104,6 +105,7 @@ func (r *Runtime) Start() error { // - the runtime should ideally run as an rpc service one can do requests, like the good ol' pman, rest in pieces. // - establish on suture a max number of retries before all initialization comes to a halt. // - remove default log flagset values. + // - subcommands MUST also set MICRO_LOG_LEVEL to error. // propagate reva log config to storage services r.c.Storage.Log.Level = r.c.Log.Level @@ -115,6 +117,7 @@ func (r *Runtime) Start() error { addServiceToken("accounts", supervisor.Add(accounts.NewSutureService(globalCtx, r.c.Accounts))) addServiceToken("glauth", supervisor.Add(glauth.NewSutureService(globalCtx, r.c.GLAuth))) addServiceToken("idp", supervisor.Add(idp.NewSutureService(globalCtx, r.c.IDP))) + addServiceToken("ocs", supervisor.Add(ocs.NewSutureService(globalCtx, r.c.OCS))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/ocs/cmd/ocs/main.go b/ocs/cmd/ocs/main.go index 17a7f5c54..aac75b441 100644 --- a/ocs/cmd/ocs/main.go +++ b/ocs/cmd/ocs/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/ocs/pkg/command" + "github.com/owncloud/ocis/ocs/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/ocs/pkg/command/root.go b/ocs/pkg/command/root.go index 71714ba39..5f27e9d42 100644 --- a/ocs/pkg/command/root.go +++ b/ocs/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "context" "os" "strings" @@ -13,9 +14,7 @@ import ( ) // Execute is the entry point for the ocis-ocs command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-ocs", Version: version.String, @@ -108,3 +107,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the ocs command to be embedded and supervised by a suture supervisor tree. +type SutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewSutureService creates a new ocs.SutureService +func NewSutureService(ctx context.Context, cfg *config.Config) SutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx // propagate the context down to the go-micro services. + return SutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s SutureService) Serve() { + if err := Execute(s.cfg); err != nil { + return + } +} + +func (s SutureService) Stop() { + s.cancel() +} diff --git a/ocs/pkg/command/server.go b/ocs/pkg/command/server.go index c2b01fcf6..c6840c981 100644 --- a/ocs/pkg/command/server.go +++ b/ocs/pkg/command/server.go @@ -145,8 +145,6 @@ func Server(cfg *config.Config) *cli.Command { http.Context(ctx), http.Config(cfg), http.Metrics(metrics), - http.Flags(flagset.RootWithConfig(config.New())), - http.Flags(flagset.ServerWithConfig(config.New())), ) if err != nil { diff --git a/ocs/pkg/config/config.go b/ocs/pkg/config/config.go index b8589533d..b06db4157 100644 --- a/ocs/pkg/config/config.go +++ b/ocs/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -51,6 +53,8 @@ type Config struct { Tracing Tracing TokenManager TokenManager Service Service + + Context context.Context } // New initializes a new configuration with or without defaults. diff --git a/ocs/pkg/flagset/flagset.go b/ocs/pkg/flagset/flagset.go index 909840335..24ba14a1d 100644 --- a/ocs/pkg/flagset/flagset.go +++ b/ocs/pkg/flagset/flagset.go @@ -10,23 +10,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"OCS_LOG_LEVEL"}, + EnvVars: []string{"OCS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", - Value: true, Usage: "Enable pretty logging", - EnvVars: []string{"OCS_LOG_PRETTY"}, + EnvVars: []string{"OCS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", - Value: true, Usage: "Enable colored logging", - EnvVars: []string{"OCS_LOG_COLOR"}, + EnvVars: []string{"OCS_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, }