diff --git a/ocis-pkg/runner/factory.go b/ocis-pkg/runner/factory.go index aad4339e979..2024c40ea1b 100644 --- a/ocis-pkg/runner/factory.go +++ b/ocis-pkg/runner/factory.go @@ -5,7 +5,6 @@ import ( "errors" "net" "net/http" - "time" ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc" ohttp "github.com/owncloud/ocis/v2/ocis-pkg/service/http" @@ -102,9 +101,8 @@ func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option) }, func() { // Since Shutdown might take some time, don't block go func() { - // give 5 secs for the shutdown to finish - // TODO: To discuss the default timeout - shutdownCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + // TODO: Provide the adjustable TimeoutDuration + shutdownCtx, cancel := context.WithTimeout(context.Background(), DefaultInterruptDuration) defer cancel() debugCh <- server.Shutdown(shutdownCtx) @@ -135,6 +133,14 @@ func NewGolangGrpcServerRunner(name string, server *grpc.Server, listener net.Li return r } +// NewRevaServiceRunner creates a new runner based on the provided reva RevaDrivenServer +// The runner will behave as described: +// * The task is to start a server and listen for connections. If the server +// can't start, the task will finish with that error. +// * The stopper will call the server's stop method and send the result to +// the task. +// * The stopper will run asynchronously because the stop method could take a +// while and we don't want to block func NewRevaServiceRunner(name string, server runtime.RevaDrivenServer, opts ...Option) *Runner { httpCh := make(chan error, 1) r := New(name, func() error { diff --git a/ocis-pkg/runner/option.go b/ocis-pkg/runner/option.go index 649deb14ed7..ae7dd8aeffa 100644 --- a/ocis-pkg/runner/option.go +++ b/ocis-pkg/runner/option.go @@ -7,11 +7,9 @@ import ( var ( // DefaultInterruptDuration is the default value for the `WithInterruptDuration` // for the "regular" runners. This global value can be adjusted if needed. - // TODO: To discuss the default timeout DefaultInterruptDuration = 20 * time.Second // DefaultGroupInterruptDuration is the default value for the `WithInterruptDuration` // for the group runners. This global value can be adjusted if needed. - // TODO: To discuss the default timeout DefaultGroupInterruptDuration = 25 * time.Second ) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 6a6b50c5ec1..7ef9c3a1e46 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -87,8 +87,6 @@ type Service struct { Log log.Logger serviceToken map[string][]suture.ServiceToken - context context.Context - cancel context.CancelFunc cfg *ociscfg.Config } @@ -110,16 +108,12 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) { log.Level(opts.Config.Log.Level), ) - globalCtx, cancelGlobal := context.WithCancel(ctx) - s := &Service{ Services: make([]serviceFuncMap, len(_waitFuncs)), Additional: make(serviceFuncMap), Log: l, serviceToken: make(map[string][]suture.ServiceToken), - context: globalCtx, - cancel: cancelGlobal, cfg: opts.Config, } @@ -364,8 +358,11 @@ func Start(ctx context.Context, o ...Option) error { } // cancel the context when a signal is received. - notifyCtx, cancel := signal.NotifyContext(ctx, runner.StopSignals...) - defer cancel() + var cancel context.CancelFunc + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } // tolerance controls backoff cycles from the supervisor. tolerance := 5 @@ -418,12 +415,12 @@ func Start(ctx context.Context, o ...Option) error { // prepare the set of services to run s.generateRunSet(s.cfg) - // there are reasons not to do this, but we have race conditions ourselves. Until we resolve them, mind the following disclaimer: + // 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 // go supervisor.Serve() // because that will briefly create a race condition as it starts up, if you try to .Add() services immediately afterward. // https://pkg.go.dev/github.com/thejerf/suture/v4@v4.0.0#Supervisor - go s.Supervisor.ServeBackground(s.context) // TODO Why does Supervisor uses s.context? + go s.Supervisor.ServeBackground(ctx) for i, service := range s.Services { scheduleServiceTokens(s, service) @@ -444,7 +441,7 @@ func Start(ctx context.Context, o ...Option) error { }() // trapShutdownCtx will block on the context-done channel for interruptions. - trapShutdownCtx(s, srv, notifyCtx) + trapShutdownCtx(s, srv, ctx) return nil } @@ -518,8 +515,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { wg.Add(1) go func() { defer wg.Done() - // TODO: To discuss the default timeout - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), runner.DefaultInterruptDuration) defer cancel() if err := srv.Shutdown(ctx); err != nil { s.Log.Error().Err(err).Msg("could not shutdown tcp listener") @@ -532,13 +528,12 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { for i := range s.serviceToken[sName] { wg.Add(1) go func() { - s.Log.Warn().Msgf("=== RemoveAndWait for %s", sName) + s.Log.Warn().Msgf("call supervisor RemoveAndWait for %s", sName) defer wg.Done() - // TODO: To discuss the default timeout - if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], 20*time.Second); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { + if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], runner.DefaultInterruptDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { s.Log.Error().Err(err).Str("service", sName).Msgf("terminating with signal: %+v", s) } - s.Log.Warn().Msgf("=== Done RemoveAndWait for %s", sName) + s.Log.Warn().Msgf("done supervisor RemoveAndWait for %s", sName) }() } } @@ -550,8 +545,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { }() select { - // TODO: To discuss the default timeout - case <-time.After(30 * time.Second): + case <-time.After(runner.DefaultGroupInterruptDuration): s.Log.Fatal().Msg("ocis graceful shutdown timeout reached, terminating") case <-done: s.Log.Info().Msg("all ocis services gracefully stopped") diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 95c2c6fdd4d..762d82d4d8c 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -28,11 +28,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 43c4847c0c6..7ddb9bde8ca 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,26 +37,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AppProviderConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("app-provider_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index b5f1c67bf6e..9aa3b8e0a81 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,27 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AppRegistryConfigFromStruct(cfg, logger) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("app-registry_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 53ea3acf22f..0765e78d4b2 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -31,11 +31,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := logging.Configure(cfg.Service.Name, cfg.Log) gr := runner.NewGroup() diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index 10cf9abf1c4..5c6bd72b800 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -47,26 +44,30 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthAppConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-app_revad", revaSrv)) - + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index f88d8a0a39c..3955613381a 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/ldap" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -40,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() @@ -61,16 +58,22 @@ func Server(cfg *config.Config) *cli.Command { } { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthBasicConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-basic_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index b036c48011f..8fa9a8258df 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthBearerConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-bearer_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index db7b284ede0..6f642522d5b 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-machine_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 44e85c0fca8..3465f4b108b 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) - - revaSrv := runtime.RunDrivenServerWithOptions(rcfg, pidFile, + // run the appropriate reva servers based on the config + rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-service_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index a9ccc0092b9..ede4ca621fb 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -63,11 +63,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index b30809da824..0da3f1075ee 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -41,11 +41,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context // prepare components if err := helpers.RegisterOcisService(ctx, cfg, logger); err != nil { diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 071342db4d3..f419da15503 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -48,11 +48,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index c461bad3cea..51a88c70394 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() @@ -53,15 +50,22 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + // run the appropriate reva servers based on the config + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("frontend_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 6cfc8f15971..ee171900def 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.GatewayConfigFromStruct(cfg, logger) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("gateway_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index fe53b9fa4a2..3d51fd7686f 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -35,11 +35,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 51bd669d488..824dc0407b5 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/ldap" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -52,26 +49,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.GroupsConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("groups_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index e39fe2571e1..6f4a4b9116a 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -38,11 +38,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index dc129f43adb..40eef62c0dc 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -60,11 +60,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 344510b6561..ae9cc9fc503 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -36,11 +36,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New(metrics.Logger(logger)) metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 3b1e590adf9..ea8bb5407d0 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -31,11 +31,11 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 3139adc97c6..70fe7cbcf79 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -59,11 +59,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 2b69cf8f8e1..c773c8b8a27 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -38,11 +38,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 4a1edad3139..1ea44da30d8 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { + // run the appropriate reva servers based on the config rCfg := revaconfig.OCMConfigFromStruct(cfg, logger) - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("ocm_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index 350f2f66ba2..946c388bf99 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -41,11 +41,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 241d774881c..e328d6b9991 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -35,11 +35,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index 563f4b65829..01ade38366a 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -39,11 +39,11 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 6d4838b07cb..3b65e45b1ec 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -109,9 +109,8 @@ func Server(cfg *config.Config) *cli.Command { ) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } @@ -192,7 +191,7 @@ func Server(cfg *config.Config) *cli.Command { server, err := proxyHTTP.Server( proxyHTTP.Handler(lh.Handler()), proxyHTTP.Logger(logger), - proxyHTTP.Context(ctx), + proxyHTTP.Context(cfg.Context), proxyHTTP.Config(cfg), proxyHTTP.Metrics(metrics.New()), proxyHTTP.Middlewares(middlewares), @@ -212,7 +211,7 @@ func Server(cfg *config.Config) *cli.Command { { debugServer, err := debug.Server( debug.Logger(logger), - debug.Context(ctx), + debug.Context(cfg.Context), debug.Config(cfg), ) if err != nil { @@ -223,7 +222,7 @@ func Server(cfg *config.Config) *cli.Command { gr.Add(runner.NewGolangHttpServerRunner("proxy_debug", debugServer)) } - grResults := gr.Run(ctx) + grResults := gr.Run(cfg.Context) // return the first non-nil error found in the results for _, grResult := range grResults { diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index d2fd2f2790b..89d19e40c3d 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -43,11 +43,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 56fc2b3816c..689175e2126 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -44,11 +44,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index aff1b3dd562..b2f969365bd 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -5,10 +5,8 @@ import ( "fmt" "os" "os/signal" - "path" "path/filepath" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -52,29 +50,35 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg, err := revaconfig.SharingConfigFromStruct(cfg, logger) if err != nil { return err } - reg := registry.GetRegistry() - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + // run the appropriate reva servers based on the config + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("sharing_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 32fe273744a..86451eeb570 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -36,11 +36,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 2a291acc7bd..3a03e55d822 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StoragePublicLinkConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-publiclink_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index 367474b3a60..bd30cced027 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageSharesConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-shares_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 2678bf7e0b5..718ee7fdfdc 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,26 +37,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageSystemFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-system_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index e6cafb82e32..e5ec4e98ad9 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/runner" @@ -41,25 +38,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageUsersConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("storage-users_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index fd680143bc7..dfb64aa6e4c 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -42,11 +42,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index af46904b000..f17779c048f 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -73,11 +73,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 730852c6eb7..31ceeaa2883 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/ldap" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -52,25 +49,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.UsersConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("users_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index f2be0fddcbf..3c987750c48 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -49,11 +49,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index e57f9b55f22..36ae0a1aa0a 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -43,11 +43,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index ef3498312a7..b6a98ab486a 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -37,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New(metrics.Logger(logger)) m.BuildInfo.WithLabelValues(version.GetString()).Set(1)