From 04632ad34cd2edcf26bbc247348058133d157b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 28 Oct 2024 11:22:58 +0100 Subject: [PATCH] make sure services have some time to deregister MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis/pkg/runtime/service/service.go | 4 +++- services/app-provider/pkg/command/server.go | 7 +++++++ services/app-registry/pkg/command/server.go | 4 ++-- services/auth-app/pkg/command/server.go | 7 +++++++ services/auth-basic/pkg/command/server.go | 7 +++++++ services/auth-bearer/pkg/command/server.go | 7 +++++++ services/auth-machine/pkg/command/server.go | 7 +++++++ services/auth-service/pkg/command/server.go | 7 +++++++ services/frontend/pkg/command/server.go | 7 +++++++ services/gateway/pkg/command/server.go | 7 +++++++ services/groups/pkg/command/server.go | 7 +++++++ services/ocm/pkg/command/server.go | 7 +++++++ services/sharing/pkg/command/server.go | 7 +++++++ services/storage-publiclink/pkg/command/server.go | 7 +++++++ services/storage-shares/pkg/command/server.go | 7 +++++++ services/storage-system/pkg/command/server.go | 7 +++++++ services/storage-users/pkg/command/server.go | 7 +++++++ services/users/pkg/command/server.go | 7 +++++++ 18 files changed, 117 insertions(+), 3 deletions(-) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 83cd6bd70a..f07fdf9882 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -6,6 +6,7 @@ import ( "net" "net/http" "net/rpc" + "os" "sort" "strings" "time" @@ -514,7 +515,8 @@ func trap(s *Service, ctx context.Context) { } } s.Log.Debug().Str("service", "runtime service").Msgf("terminating with signal: %v", s) - //os.Exit(0) // this seems to cause an early exit that prevents services from shitting down properly + time.Sleep(3 * time.Second) // give the services time to deregister + os.Exit(0) // FIXME this cause an early exit that prevents services from shitting down properly } // pingNats will attempt to connect to nats, blocking until a connection is established diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 4711b01602..73b7045c65 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AppProviderConfigFromStruct(cfg) diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 0322d6c0eb..4758411a55 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -41,11 +41,11 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled gr.Add(func() error { <-ctx.Done() - cancel() return nil - }, func(err error) { + }, func(_ error) { }) gr.Add(func() error { diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index 96ead3230c..e337309beb 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -49,6 +49,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthAppConfigFromStruct(cfg) diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index 37204df408..0a8d8bf0cb 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -54,6 +54,13 @@ func Server(cfg *config.Config) *cli.Command { } } + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthBasicConfigFromStruct(cfg) diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 8056387f96..3ca39dc70e 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthBearerConfigFromStruct(cfg) diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 84d039a20a..108948fd61 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 887cdd1cb4..192dc7576a 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -46,6 +46,13 @@ func Server(cfg *config.Config) *cli.Command { rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { runtime.RunWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger), diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index e9597d7042..bd4a05c545 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -46,6 +46,13 @@ func Server(cfg *config.Config) *cli.Command { return err } + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") reg := registry.GetRegistry() diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 905db3bb3b..2c909601f7 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.GatewayConfigFromStruct(cfg, logger) diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index b5d6030d2e..ae4f7a045d 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -54,6 +54,13 @@ func Server(cfg *config.Config) *cli.Command { } } + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.GroupsConfigFromStruct(cfg) diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index eb12be1e3d..370d419185 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -43,6 +43,13 @@ func Server(cfg *config.Config) *cli.Command { rCfg := revaconfig.OCMConfigFromStruct(cfg, logger) + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") reg := registry.GetRegistry() diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 4948f813d3..7e12a76729 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -54,6 +54,13 @@ func Server(cfg *config.Config) *cli.Command { } } + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg, err := revaconfig.SharingConfigFromStruct(cfg, logger) diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index ed1621caee..9bc1283ad0 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StoragePublicLinkConfigFromStruct(cfg) diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index 1311ef99be..6de970d0e4 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageSharesConfigFromStruct(cfg) diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 88efdf0510..2f9ba7e5de 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -41,6 +41,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageSystemFromStruct(cfg) diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index a100cc4f59..a2aa036cec 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -43,6 +43,13 @@ func Server(cfg *config.Config) *cli.Command { defer cancel() + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageUsersConfigFromStruct(cfg) diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 7cabbfeeac..71d2d47129 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -54,6 +54,13 @@ func Server(cfg *config.Config) *cli.Command { } } + // make sure the run group executes all interrupt handlers when the context is canceled + gr.Add(func() error { + <-ctx.Done() + return nil + }, func(_ error) { + }) + gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.UsersConfigFromStruct(cfg)