diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 3b854d587f..c65202a2a6 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -12,6 +12,7 @@ import ( onlyoffice "github.com/owncloud/ocis/onlyoffice/pkg/command" proxy "github.com/owncloud/ocis/proxy/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" + store "github.com/owncloud/ocis/store/pkg/command" "github.com/thejerf/suture" @@ -41,8 +42,8 @@ var ( "idp", // done "ocs", // done "onlyoffice", // done - "proxy", - "settings", // done + "proxy", // done + "settings", // done "store", "storage-metadata", // done "storage-frontend", @@ -122,6 +123,7 @@ func (r *Runtime) Start() error { addServiceToken("ocs", supervisor.Add(ocs.NewSutureService(globalCtx, r.c.OCS))) addServiceToken("onlyoffice", supervisor.Add(onlyoffice.NewSutureService(globalCtx, r.c.Onlyoffice))) addServiceToken("proxy", supervisor.Add(proxy.NewSutureService(globalCtx, r.c.Proxy))) + addServiceToken("store", supervisor.Add(store.NewSutureService(globalCtx, r.c.Store))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 7fd5c6461b..40057a361b 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/pkg/command/root.go @@ -109,14 +109,14 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } -// SutureService allows for the onlyoffice command to be embedded and supervised by a suture supervisor tree. +// SutureService allows for the proxy 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 onlyoffice.SutureService +// NewSutureService creates a new proxy.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. diff --git a/store/cmd/store/main.go b/store/cmd/store/main.go index a034fb12f5..ad2549012a 100644 --- a/store/cmd/store/main.go +++ b/store/cmd/store/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/store/pkg/command" + "github.com/owncloud/ocis/store/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/store/pkg/command/root.go b/store/pkg/command/root.go index 6c32046818..bc548b5ae1 100644 --- a/store/pkg/command/root.go +++ b/store/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-store command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-store", Version: version.String, @@ -108,3 +107,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the store 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 store.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/store/pkg/command/server.go b/store/pkg/command/server.go index c693d47fa2..df42dfffda 100644 --- a/store/pkg/command/server.go +++ b/store/pkg/command/server.go @@ -139,8 +139,6 @@ func Server(cfg *config.Config) *cli.Command { grpc.Context(ctx), grpc.Config(cfg), grpc.Metrics(metrics), - grpc.Flags(flagset.RootWithConfig(config.New())), - grpc.Flags(flagset.ServerWithConfig(config.New())), ) gr.Add(server.Run, func(_ error) { diff --git a/store/pkg/config/config.go b/store/pkg/config/config.go index 30ca9ffdb8..f16e27bb3e 100644 --- a/store/pkg/config/config.go +++ b/store/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -46,6 +48,8 @@ type Config struct { Tracing Tracing Datapath string Service Service + + Context context.Context } // New initializes a new configuration with or without defaults. diff --git a/store/pkg/flagset/flagset.go b/store/pkg/flagset/flagset.go index cfb8c7bd4e..d664b82356 100644 --- a/store/pkg/flagset/flagset.go +++ b/store/pkg/flagset/flagset.go @@ -17,23 +17,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"STORE_LOG_LEVEL"}, + EnvVars: []string{"STORE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", - Value: true, Usage: "Enable pretty logging", - EnvVars: []string{"STORE_LOG_PRETTY"}, + EnvVars: []string{"STORE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", - Value: true, Usage: "Enable colored logging", - EnvVars: []string{"STORE_LOG_COLOR"}, + EnvVars: []string{"STORE_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, }