diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index ab161e8233..50d4fd9058 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -85,8 +85,6 @@ type Service struct { Log log.Logger serviceToken map[string][]suture.ServiceToken - context context.Context - cancel context.CancelFunc cfg *occfg.Config } @@ -108,16 +106,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, } @@ -362,8 +356,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 @@ -416,12 +413,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) @@ -442,7 +439,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 } @@ -516,8 +513,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") @@ -530,13 +526,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) }() } } @@ -548,8 +543,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/pkg/runner/factory.go b/pkg/runner/factory.go index 37767ddde4..3931c39c1d 100644 --- a/pkg/runner/factory.go +++ b/pkg/runner/factory.go @@ -5,7 +5,6 @@ import ( "errors" "net" "net/http" - "time" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" ohttp "github.com/opencloud-eu/opencloud/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/pkg/runner/option.go b/pkg/runner/option.go index 649deb14ed..ae7dd8aeff 100644 --- a/pkg/runner/option.go +++ b/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/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 05f3186c0d..9d22a5de6c 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 0790f3b42d..66d1a8fea9 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/opencloud-eu/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 aa6e2c91f7..5642063e9b 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 78f05df855..4dbced80ac 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 51390cd964..8ca8b6befd 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 aa86c85395..eba9374de7 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/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 96d4028c6e..f0ed477831 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 0b3ce11d0a..6dd71e8877 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 90f24d83e7..d097a4c6fa 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 f9e1e8a7cf..fbf1ab461a 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 2bb369956c..79efd6ae27 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/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 // prepare components if err := helpers.RegisterOpenCloudService(ctx, cfg, logger); err != nil { diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index eaa85e2480..c6cf336fc9 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 ea0da1b7a7..0d04efb549 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/opencloud-eu/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 e131a12749..f07cba2dc8 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 4eb5c5c1d3..77247a8a2c 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 2282e786e8..b5ef09d2c5 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/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 85546df7b2..e87affc734 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 db12bcc0c6..fc47ee8936 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 647637bd42..be1d589344 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 56c0618d96..8ab7709755 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 f49bfd4cc0..2a7e70edff 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 9b37eaeb29..db3f76af6e 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 f0f955eea4..05f42e12b2 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 a8df3fde12..01abae2ace 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 eaf49364be..0871ffa556 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 9a8a72d6ef..af881d8fe2 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -37,11 +37,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 31fa3a6699..e6f9e72319 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 261b65b635..cef5f3c2fe 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 67bd695378..14634f2b1e 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 6b29f4ace5..edc28a01be 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 4579567d3a..1b40de0af8 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 50b937dbf0..97ff68a690 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 1abce31c41..7347252e57 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 f8882b841c..c96a376aa3 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/opencloud-eu/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 338e0f6d76..c029c04b70 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/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 cf1410bd81..d9112d666c 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 d99c6b3125..ff37ac2283 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -71,11 +71,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 e215b5e385..7c35c1f5b3 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/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/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 9bffe86bdc..9c7f266199 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 48f0e0795a..fd304398fd 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 1c58a4ee3c..e5d17e6fc6 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)