From 8c9f266dedddb6f94fb52116cb0297a1d65c301f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 7 Oct 2025 12:07:01 +0200 Subject: [PATCH] allow specifying a shutdown order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- opencloud/pkg/runtime/service/service.go | 18 ++++++++++++++++++ pkg/config/config.go | 11 ++++++----- pkg/config/defaultconfig.go | 5 +++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index 5d244e1ace..16ff8656fb 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -521,6 +521,24 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error { s.Log.Debug().Msg("runtime listener shutdown done") }() + // shutdown services in the order defined in the config + // any services not listed will be shutdown in parallel afterwards + for _, sName := range s.cfg.Runtime.ShutdownOrder { + if _, ok := s.serviceToken[sName]; !ok { + s.Log.Warn().Str("service", sName).Msg("unknown service for ordered shutdown, skipping") + continue + } + for i := range s.serviceToken[sName] { + if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], _defaultShutdownTimeoutDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { + s.Log.Error().Err(err).Str("service", sName).Msg("could not shutdown service in order, skipping to next") + // continue shutting down other services + continue + } + s.Log.Debug().Str("service", sName).Msg("graceful ordered shutdown for service done") + } + delete(s.serviceToken, sName) + } + for sName := range s.serviceToken { for i := range s.serviceToken[sName] { wg.Add(1) diff --git a/pkg/config/config.go b/pkg/config/config.go index 26b019f12d..b07d561dcf 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -50,11 +50,12 @@ type Mode int // Runtime configures the OpenCloud runtime when running in supervised mode. type Runtime struct { - Port string `yaml:"port" env:"OC_RUNTIME_PORT" desc:"The TCP port at which OpenCloud will be available" introductionVersion:"1.0.0"` - Host string `yaml:"host" env:"OC_RUNTIME_HOST" desc:"The host at which OpenCloud will be available" introductionVersion:"1.0.0"` - Services []string `yaml:"services" env:"OC_RUN_EXTENSIONS;OC_RUN_SERVICES" desc:"A comma-separated list of service names. Will start only the listed services." introductionVersion:"1.0.0"` - Disabled []string `yaml:"disabled_services" env:"OC_EXCLUDE_RUN_SERVICES" desc:"A comma-separated list of service names. Will start all default services except of the ones listed. Has no effect when OC_RUN_SERVICES is set." introductionVersion:"1.0.0"` - Additional []string `yaml:"add_services" env:"OC_ADD_RUN_SERVICES" desc:"A comma-separated list of service names. Will add the listed services to the default configuration. Has no effect when OC_RUN_SERVICES is set. Note that one can add services not started by the default list and exclude services from the default list by using both envvars at the same time." introductionVersion:"1.0.0"` + Port string `yaml:"port" env:"OC_RUNTIME_PORT" desc:"The TCP port at which OpenCloud will be available" introductionVersion:"1.0.0"` + Host string `yaml:"host" env:"OC_RUNTIME_HOST" desc:"The host at which OpenCloud will be available" introductionVersion:"1.0.0"` + Services []string `yaml:"services" env:"OC_RUN_EXTENSIONS;OC_RUN_SERVICES" desc:"A comma-separated list of service names. Will start only the listed services." introductionVersion:"1.0.0"` + Disabled []string `yaml:"disabled_services" env:"OC_EXCLUDE_RUN_SERVICES" desc:"A comma-separated list of service names. Will start all default services except of the ones listed. Has no effect when OC_RUN_SERVICES is set." introductionVersion:"1.0.0"` + Additional []string `yaml:"add_services" env:"OC_ADD_RUN_SERVICES" desc:"A comma-separated list of service names. Will add the listed services to the default configuration. Has no effect when OC_RUN_SERVICES is set. Note that one can add services not started by the default list and exclude services from the default list by using both envvars at the same time." introductionVersion:"1.0.0"` + ShutdownOrder []string `yaml:"shutdown_order" env:"OC_SHUTDOWN_ORDER" desc:"A comma-separated list of service names defining the order in which services are shut down. Services not listed will be stopped after the listed ones in random order." introductionVersion:"%%NEXT%%"` } // Config combines all available configuration parts. diff --git a/pkg/config/defaultconfig.go b/pkg/config/defaultconfig.go index 00cade7fb3..cc94e0bec2 100644 --- a/pkg/config/defaultconfig.go +++ b/pkg/config/defaultconfig.go @@ -50,8 +50,9 @@ func DefaultConfig() *Config { return &Config{ OpenCloudURL: "https://localhost:9200", Runtime: Runtime{ - Port: "9250", - Host: "localhost", + Port: "9250", + Host: "localhost", + ShutdownOrder: []string{"proxy"}, }, Reva: &shared.Reva{ Address: "eu.opencloud.api.gateway",