diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 83cd6bd70..f07fdf988 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 4711b0160..73b7045c6 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 0322d6c0e..4758411a5 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 96ead3230..e337309be 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 37204df40..0a8d8bf0c 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 8056387f9..3ca39dc70 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 84d039a20..108948fd6 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 887cdd1cb..192dc7576 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 e9597d704..bd4a05c54 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 905db3bb3..2c909601f 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 b5d6030d2..ae4f7a045 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 eb12be1e3..370d41918 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 4948f813d..7e12a7672 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 ed1621cae..9bc1283ad 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 1311ef99b..6de970d0e 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 88efdf051..2f9ba7e5d 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 a100cc4f5..a2aa036ce 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 7cabbfeea..71d2d4712 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)