From 04bf15d27377a766bda6a061495f461e3883ba35 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 7 Aug 2024 15:04:05 +0200 Subject: [PATCH 01/23] feat(plugins): bump go-micro plugins pkg Signed-off-by: jkoberg --- changelog/unreleased/bump-gomicro-plugins.md | 5 ++ go.mod | 2 +- go.sum | 4 +- .../plugins/v4/store/nats-js-kv/keys.go | 44 +++++++---- .../plugins/v4/store/nats-js-kv/nats.go | 77 +++++++++++++++++-- .../plugins/v4/store/nats-js-kv/options.go | 8 ++ vendor/modules.txt | 5 +- 7 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 changelog/unreleased/bump-gomicro-plugins.md diff --git a/changelog/unreleased/bump-gomicro-plugins.md b/changelog/unreleased/bump-gomicro-plugins.md new file mode 100644 index 00000000000..d4d9b20be71 --- /dev/null +++ b/changelog/unreleased/bump-gomicro-plugins.md @@ -0,0 +1,5 @@ +Enhancement: Bump go-micro plugins pkg + +Bump plugins pkg to include fix for cache delete + +https://github.com/owncloud/ocis/pull/9756 diff --git a/go.mod b/go.mod index 48989092a02..2617182b084 100644 --- a/go.mod +++ b/go.mod @@ -351,7 +351,7 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 +replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 replace github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6 diff --git a/go.sum b/go.sum index d01adce1965..d342fda3133 100644 --- a/go.sum +++ b/go.sum @@ -1593,8 +1593,8 @@ github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= -github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 h1:Czv6AW9Suj6npWd5BLZjobdD78c2RdzBeKBgkq3jYZk= -github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348/go.mod h1:Goi4eJ9SrKkxE6NsAVqBVNxfQFbwb7UbyII6743ldgM= +github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 h1:pfI8Z5yavO6fU6vDGlWhZ4BgDlvj8c6xB7J57HfTPwA= +github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90/go.mod h1:pjcozWijkNPbEtX5SIQaxEW/h8VAVZYTLx+70bmB3LY= github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= diff --git a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/keys.go b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/keys.go index 8fd6f1aa9a1..8eb2869ca4b 100644 --- a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/keys.go +++ b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/keys.go @@ -6,24 +6,24 @@ import ( ) // NatsKey is a convenience function to create a key for the nats kv store. -func NatsKey(table, microkey string) string { - return NewKey(table, microkey, "").NatsKey() +func (n *natsStore) NatsKey(table, microkey string) string { + return n.NewKey(table, microkey, "").NatsKey() } // MicroKey is a convenience function to create a key for the micro interface. -func MicroKey(table, natskey string) string { - return NewKey(table, "", natskey).MicroKey() +func (n *natsStore) MicroKey(table, natskey string) string { + return n.NewKey(table, "", natskey).MicroKey() } // MicroKeyFilter is a convenience function to create a key for the micro interface. // It returns false if the key does not match the table, prefix or suffix. -func MicroKeyFilter(table, natskey string, prefix, suffix string) (string, bool) { - k := NewKey(table, "", natskey) +func (n *natsStore) MicroKeyFilter(table, natskey string, prefix, suffix string) (string, bool) { + k := n.NewKey(table, "", natskey) return k.MicroKey(), k.Check(table, prefix, suffix) } // Key represents a key in the store. -// They are used to convert nats keys (base64 encoded) to micro keys (plain text - no table prefix) and vice versa. +// They are used to convert nats keys (base32 encoded) to micro keys (plain text - no table prefix) and vice versa. type Key struct { // Plain is the plain key as requested by the go-micro interface. Plain string @@ -34,7 +34,7 @@ type Key struct { } // NewKey creates a new key. Either plain or encoded must be set. -func NewKey(table string, plain, encoded string) *Key { +func (n *natsStore) NewKey(table string, plain, encoded string) *Key { k := &Key{ Plain: plain, Encoded: encoded, @@ -43,9 +43,9 @@ func NewKey(table string, plain, encoded string) *Key { switch { case k.Plain != "": k.Full = getKey(k.Plain, table) - k.Encoded = encode(k.Full) + k.Encoded = encode(k.Full, n.encoding) case k.Encoded != "": - k.Full = decode(k.Encoded) + k.Full = decode(k.Encoded, n.encoding) k.Plain = trimKey(k.Full, table) } @@ -79,17 +79,27 @@ func (k *Key) Check(table, prefix, suffix string) bool { return true } -func encode(s string) string { - return base32.StdEncoding.EncodeToString([]byte(s)) +func encode(s string, alg string) string { + switch alg { + case "base32": + return base32.StdEncoding.EncodeToString([]byte(s)) + default: + return s + } } -func decode(s string) string { - b, err := base32.StdEncoding.DecodeString(s) - if err != nil { +func decode(s string, alg string) string { + switch alg { + case "base32": + b, err := base32.StdEncoding.DecodeString(s) + if err != nil { + return s + } + + return string(b) + default: return s } - - return string(b) } func getKey(key, table string) string { diff --git a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/nats.go b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/nats.go index aa7d5045359..f7ee7a17227 100644 --- a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/nats.go +++ b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/nats.go @@ -30,6 +30,7 @@ type natsStore struct { sync.Once sync.RWMutex + encoding string ttl time.Duration storageType nats.StorageType description string @@ -143,6 +144,10 @@ func (n *natsStore) setOption(opts ...store.Option) { n.description = text } + if encoding, ok := n.opts.Context.Value(keyEncodeOptionsKey{}).(string); ok { + n.encoding = encoding + } + // Assign store option server addresses to nats options if len(n.opts.Nodes) > 0 { n.nopts.Url = "" @@ -238,8 +243,8 @@ func (n *natsStore) Write(rec *store.Record, opts ...store.WriteOption) error { return errors.Wrap(err, "Failed to marshal object") } - if _, err := store.Put(NatsKey(opt.Table, rec.Key), b); err != nil { - return errors.Wrapf(err, "Failed to store data in bucket '%s'", NatsKey(opt.Table, rec.Key)) + if _, err := store.Put(n.NatsKey(opt.Table, rec.Key), b); err != nil { + return errors.Wrapf(err, "Failed to store data in bucket '%s'", n.NatsKey(opt.Table, rec.Key)) } return nil @@ -280,7 +285,7 @@ func (n *natsStore) Delete(key string, opts ...store.DeleteOption) error { return ErrBucketNotFound } - if err := store.Delete(NatsKey(opt.Table, key)); err != nil { + if err := store.Delete(n.NatsKey(opt.Table, key)); err != nil { return errors.Wrap(err, "Failed to delete data") } @@ -330,6 +335,66 @@ func (n *natsStore) String() string { return "NATS JetStream KeyValueStore" } +// StoreUpdate is the update type for the store. +type StoreUpdate struct { + Value KeyValueEnvelope + Action string +} + +// WatchAll exposes the watcher interface from the underlying JetStreamContext. +func (n *natsStore) WatchAll(bucket string, opts ...nats.WatchOpt) (<-chan *StoreUpdate, func() error, error) { + if bucket == "" { + return nil, nil, errors.New("multi bucket watching is not supported") + } + + if err := n.initConn(); err != nil { + return nil, nil, err + } + + b, err := n.js.KeyValue(bucket) + if err != nil { + return nil, nil, errors.Wrap(err, "Failed to get bucket") + } + + w, err := b.WatchAll(opts...) + if err != nil { + return nil, nil, errors.Wrap(err, "Failed to watch bucket") + } + + ch := make(chan *StoreUpdate) + go func() { + for u := range w.Updates() { + if u == nil { + continue + } + + var action string + var kv KeyValueEnvelope + switch u.Operation() { + case nats.KeyValuePut: + action = "create" + if err := json.Unmarshal(u.Value(), &kv); err != nil { + continue + } + case nats.KeyValueDelete: + fallthrough + case nats.KeyValuePurge: + action = "delete" + kv = KeyValueEnvelope{ + Key: n.NewKey(n.opts.Table, "", u.Key()).MicroKey(), + } + } + + ch <- &StoreUpdate{ + Value: kv, + Action: action, + } + } + }() + + return ch, w.Stop, nil +} + // thread safe way to initialize the connection. func (n *natsStore) initConn() error { if n.hasConn() { @@ -392,7 +457,7 @@ func (n *natsStore) mustGetBucket(kv *nats.KeyValueConfig) (nats.KeyValue, error func (n *natsStore) getRecord(bucket nats.KeyValue, key string) (*store.Record, bool, error) { obj, err := bucket.Get(key) if errors.Is(err, nats.ErrKeyNotFound) { - return nil, false, nil + return nil, false, store.ErrNotFound } else if err != nil { return nil, false, errors.Wrap(err, "Failed to get object from bucket") } @@ -415,7 +480,7 @@ func (n *natsStore) getRecord(bucket nats.KeyValue, key string) (*store.Record, func (n *natsStore) natsKeys(bucket nats.KeyValue, table, key string, prefix, suffix bool) ([]string, error) { if !suffix && !prefix { - return []string{NatsKey(table, key)}, nil + return []string{n.NatsKey(table, key)}, nil } toS := func(s string, b bool) string { @@ -449,7 +514,7 @@ func (n *natsStore) getKeys(bucket nats.KeyValue, table string, prefix, suffix s microKeys := make([]string, 0, len(names)) for _, k := range names { - mkey, ok := MicroKeyFilter(table, k, prefix, suffix) + mkey, ok := n.MicroKeyFilter(table, k, prefix, suffix) if !ok { continue } diff --git a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/options.go b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/options.go index 424ce947fda..a9c9ca610a2 100644 --- a/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/options.go +++ b/vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/options.go @@ -14,6 +14,7 @@ type kvOptionsKey struct{} type ttlOptionsKey struct{} type memoryOptionsKey struct{} type descriptionOptionsKey struct{} +type keyEncodeOptionsKey struct{} // NatsOptions accepts nats.Options. func NatsOptions(opts nats.Options) store.Option { @@ -61,6 +62,13 @@ func DefaultDescription(text string) store.Option { return setStoreOption(descriptionOptionsKey{}, text) } +// EncodeKeys will "base32" encode the keys. +// This is to work around limited characters usable as keys for the natsjs kv store. +// See details here: https://docs.nats.io/nats-concepts/subjects#characters-allowed-for-subject-names +func EncodeKeys() store.Option { + return setStoreOption(keyEncodeOptionsKey{}, "base32") +} + // DeleteBucket will use the key passed to Delete as a bucket (database) name, // // and delete the bucket. diff --git a/vendor/modules.txt b/vendor/modules.txt index e6a549ef144..46f553b4ec1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -947,7 +947,7 @@ github.com/go-micro/plugins/v4/server/http # github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20231129143103-d72facc652f0 ## explicit; go 1.21 github.com/go-micro/plugins/v4/store/nats-js -# github.com/go-micro/plugins/v4/store/nats-js-kv v0.0.0-00010101000000-000000000000 => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 +# github.com/go-micro/plugins/v4/store/nats-js-kv v0.0.0-00010101000000-000000000000 => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 ## explicit; go 1.21 github.com/go-micro/plugins/v4/store/nats-js-kv # github.com/go-micro/plugins/v4/store/redis v1.2.1 @@ -1673,6 +1673,7 @@ github.com/rogpeppe/go-internal/internal/syscall/windows github.com/rogpeppe/go-internal/internal/syscall/windows/sysdll github.com/rogpeppe/go-internal/lockedfile github.com/rogpeppe/go-internal/lockedfile/internal/filelock +github.com/rogpeppe/go-internal/semver # github.com/rs/cors v1.10.1 ## explicit; go 1.13 github.com/rs/cors @@ -2334,6 +2335,6 @@ stash.kopano.io/kgol/oidc-go # stash.kopano.io/kgol/rndm v1.1.2 ## explicit; go 1.13 stash.kopano.io/kgol/rndm -# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 +# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90 # github.com/studio-b12/gowebdav => github.com/aduffeck/gowebdav v0.0.0-20231215102054-212d4a4374f6 # github.com/egirna/icap-client => github.com/fschade/icap-client v0.0.0-20240123094924-5af178158eaf From 4f699dd0445bfff701ba2d3aa62676841d35d6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 6 Aug 2024 12:55:42 +0200 Subject: [PATCH 02/23] use less selectors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/use-less-selectors.md | 5 ++++ services/proxy/pkg/command/server.go | 28 +++++++++++------- services/proxy/pkg/router/router.go | 34 ++++++++++------------ services/proxy/pkg/user/backend/cs3.go | 17 ++++++----- 4 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 changelog/unreleased/use-less-selectors.md diff --git a/changelog/unreleased/use-less-selectors.md b/changelog/unreleased/use-less-selectors.md new file mode 100644 index 00000000000..a2b650fab3f --- /dev/null +++ b/changelog/unreleased/use-less-selectors.md @@ -0,0 +1,5 @@ +Bugfix: use less selectors that watch the registry + +The proxy now shares the service selector for all host lookups. + +https://github.com/owncloud/ocis/pull/9741 diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index a3739163e9a..2ce79a0a52a 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -14,10 +14,6 @@ import ( "github.com/go-chi/render" "github.com/justinas/alice" "github.com/oklog/run" - "github.com/urfave/cli/v2" - microstore "go-micro.dev/v4/store" - "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" - "go.opentelemetry.io/otel/trace" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/v2/pkg/store" @@ -43,6 +39,11 @@ import ( "github.com/owncloud/ocis/v2/services/proxy/pkg/user/backend" "github.com/owncloud/ocis/v2/services/proxy/pkg/userroles" ocisstore "github.com/owncloud/ocis/v2/services/store/pkg/store" + "github.com/urfave/cli/v2" + "go-micro.dev/v4/selector" + microstore "go-micro.dev/v4/store" + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + "go.opentelemetry.io/otel/trace" ) // Server is the entrypoint for the server command. @@ -148,7 +149,8 @@ func Server(cfg *config.Config) *cli.Command { } { - middlewares := loadMiddlewares(ctx, logger, cfg, userInfoCache, signingKeyStore, traceProvider, *m) + middlewares := loadMiddlewares(logger, cfg, userInfoCache, signingKeyStore, traceProvider, *m) + server, err := proxyHTTP.Server( proxyHTTP.Handler(lh.handler()), proxyHTTP.Logger(logger), @@ -289,9 +291,13 @@ func (h *StaticRouteHandler) backchannelLogout(w http.ResponseWriter, r *http.Re render.JSON(w, r, nil) } -func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config, userInfoCache, signingKeyStore microstore.Store, traceProvider trace.TracerProvider, metrics metrics.Metrics) alice.Chain { +func loadMiddlewares(logger log.Logger, cfg *config.Config, + userInfoCache, signingKeyStore microstore.Store, traceProvider trace.TracerProvider, metrics metrics.Metrics) alice.Chain { rolesClient := settingssvc.NewRoleService("com.owncloud.api.settings", cfg.GrpcClient) policiesProviderClient := policiessvc.NewPoliciesProviderService("com.owncloud.api.policies", cfg.GrpcClient) + + reg := registry.GetRegistry() + gatewaySelector, err := pool.GatewaySelector( cfg.Reva.Address, append( @@ -302,16 +308,16 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config, if err != nil { logger.Fatal().Err(err).Msg("Failed to get gateway selector") } - if err != nil { - logger.Fatal().Err(err). - Msg("Failed to create token manager") - } + + serviceSelector := selector.NewSelector(selector.Registry(reg)) + var userProvider backend.UserBackend switch cfg.AccountBackend { case "cs3": userProvider = backend.NewCS3UserBackend( backend.WithLogger(logger), backend.WithRevaGatewaySelector(gatewaySelector), + backend.WithSelector(serviceSelector), backend.WithMachineAuthAPIKey(cfg.MachineAuthAPIKey), backend.WithOIDCissuer(cfg.OIDC.Issuer), backend.WithServiceAccount(cfg.ServiceAccount), @@ -408,7 +414,7 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config, cfg.OIDC.RewriteWellKnown, oidcHTTPClient, ), - router.Middleware(cfg.PolicySelector, cfg.Policies, logger), + router.Middleware(serviceSelector, cfg.PolicySelector, cfg.Policies, logger), middleware.Authentication( authenticators, middleware.CredentialsByUserAgent(cfg.AuthMiddleware.CredentialsByUserAgent), diff --git a/services/proxy/pkg/router/router.go b/services/proxy/pkg/router/router.go index 85734ae5d46..cab3e96e4f0 100644 --- a/services/proxy/pkg/router/router.go +++ b/services/proxy/pkg/router/router.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" "github.com/owncloud/ocis/v2/services/proxy/pkg/proxy/policy" "go-micro.dev/v4/selector" @@ -20,8 +19,8 @@ type routingInfoCtxKey struct{} var noInfo = RoutingInfo{} // Middleware returns a HTTP middleware containing the router. -func Middleware(policySelector *config.PolicySelector, policies []config.Policy, logger log.Logger) func(http.Handler) http.Handler { - router := New(policySelector, policies, logger) +func Middleware(serviceSelector selector.Selector, policySelectorCfg *config.PolicySelector, policies []config.Policy, logger log.Logger) func(http.Handler) http.Handler { + router := New(serviceSelector, policySelectorCfg, policies, logger) return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ri, ok := router.Route(r) @@ -36,11 +35,11 @@ func Middleware(policySelector *config.PolicySelector, policies []config.Policy, // New creates a new request router. // It initializes the routes before returning the router. -func New(policySelector *config.PolicySelector, policies []config.Policy, logger log.Logger) Router { - if policySelector == nil { +func New(serviceSelector selector.Selector, policySelectorCfg *config.PolicySelector, policies []config.Policy, logger log.Logger) Router { + if policySelectorCfg == nil { firstPolicy := policies[0].Name logger.Warn().Str("policy", firstPolicy).Msg("policy-selector not configured. Will always use first policy") - policySelector = &config.PolicySelector{ + policySelectorCfg = &config.PolicySelector{ Static: &config.StaticSelectorConf{ Policy: firstPolicy, }, @@ -48,18 +47,19 @@ func New(policySelector *config.PolicySelector, policies []config.Policy, logger } logger.Debug(). - Interface("selector_config", policySelector). + Interface("selector_config", policySelectorCfg). Msg("loading policy-selector") - selector, err := policy.LoadSelector(policySelector) + policySelector, err := policy.LoadSelector(policySelectorCfg) if err != nil { logger.Fatal().Err(err).Msg("Could not load policy-selector") } r := Router{ - logger: logger, - rewriters: make(map[string]map[config.RouteType]map[string][]RoutingInfo), - policySelector: selector, + logger: logger, + rewriters: make(map[string]map[config.RouteType]map[string][]RoutingInfo), + policySelector: policySelector, + serviceSelector: serviceSelector, } for _, pol := range policies { for _, route := range pol.Routes { @@ -103,9 +103,10 @@ func (r RoutingInfo) IsRouteUnprotected() bool { // Router handles the routing of HTTP requests according to the given policies. type Router struct { - logger log.Logger - rewriters map[string]map[config.RouteType]map[string][]RoutingInfo - policySelector policy.Selector + logger log.Logger + rewriters map[string]map[config.RouteType]map[string][]RoutingInfo + policySelector policy.Selector + serviceSelector selector.Selector } func (rt Router) addHost(policy string, target *url.URL, route config.Route) { @@ -124,16 +125,13 @@ func (rt Router) addHost(policy string, target *url.URL, route config.Route) { rt.rewriters[policy][routeType][route.Method] = make([]RoutingInfo, 0) } - reg := registry.GetRegistry() - sel := selector.NewSelector(selector.Registry(reg)) - rt.rewriters[policy][routeType][route.Method] = append(rt.rewriters[policy][routeType][route.Method], RoutingInfo{ endpoint: route.Endpoint, unprotected: route.Unprotected, rewrite: func(req *httputil.ProxyRequest) { if route.Service != "" { // select next node - next, err := sel.Select(route.Service) + next, err := rt.serviceSelector.Select(route.Service) if err != nil { rt.logger.Error().Err(err). Str("service", route.Service). diff --git a/services/proxy/pkg/user/backend/cs3.go b/services/proxy/pkg/user/backend/cs3.go index c27183aeefd..89c16c03304 100644 --- a/services/proxy/pkg/user/backend/cs3.go +++ b/services/proxy/pkg/user/backend/cs3.go @@ -13,13 +13,11 @@ import ( revactx "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" libregraph "github.com/owncloud/libre-graph-api-go" - "go-micro.dev/v4/selector" - "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/ocis-pkg/oidc" - "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/services/graph/pkg/errorcode" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" + "go-micro.dev/v4/selector" ) type cs3backend struct { @@ -34,6 +32,7 @@ type Option func(o *Options) type Options struct { logger log.Logger gatewaySelector pool.Selectable[gateway.GatewayAPIClient] + selector selector.Selector machineAuthAPIKey string oidcISS string serviceAccount config.ServiceAccount @@ -53,6 +52,13 @@ func WithRevaGatewaySelector(selectable pool.Selectable[gateway.GatewayAPIClient } } +// WithSelector set the Selector option +func WithSelector(selector selector.Selector) Option { + return func(o *Options) { + o.selector = selector + } +} + // WithMachineAuthAPIKey configures the machine auth API key func WithMachineAuthAPIKey(ma string) Option { return func(o *Options) { @@ -81,12 +87,9 @@ func NewCS3UserBackend(opts ...Option) UserBackend { o(&opt) } - reg := registry.GetRegistry() - sel := selector.NewSelector(selector.Registry(reg)) - b := cs3backend{ Options: opt, - graphSelector: sel, + graphSelector: opt.selector, } return &b From b3f24122b1ebb15b0dc31bae038ff15e86e064fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 6 Aug 2024 13:33:18 +0200 Subject: [PATCH 03/23] fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/proxy/pkg/proxy/proxy_integration_test.go | 7 ++++++- services/proxy/pkg/router/router_test.go | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/services/proxy/pkg/proxy/proxy_integration_test.go b/services/proxy/pkg/proxy/proxy_integration_test.go index e26dee24390..97e776f81a7 100644 --- a/services/proxy/pkg/proxy/proxy_integration_test.go +++ b/services/proxy/pkg/proxy/proxy_integration_test.go @@ -10,8 +10,10 @@ import ( "testing" "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" "github.com/owncloud/ocis/v2/services/proxy/pkg/router" + "go-micro.dev/v4/selector" ) func TestProxyIntegration(t *testing.T) { @@ -111,12 +113,15 @@ func TestProxyIntegration(t *testing.T) { expectProxyTo("http://users.example.com/user/1234"), } + reg := registry.GetRegistry() + sel := selector.NewSelector(selector.Registry(reg)) + for k := range tests { t.Run(tests[k].id, func(t *testing.T) { t.Parallel() tc := tests[k] - rt := router.Middleware(nil, tc.conf, log.NewLogger()) + rt := router.Middleware(sel, nil, tc.conf, log.NewLogger()) rp := newTestProxy(testConfig(tc.conf), func(req *http.Request) *http.Response { if got, want := req.URL.String(), tc.expect.String(); got != want { t.Errorf("Proxied url should be %v got %v", want, got) diff --git a/services/proxy/pkg/router/router_test.go b/services/proxy/pkg/router/router_test.go index 2652db56aac..303ba293bd5 100644 --- a/services/proxy/pkg/router/router_test.go +++ b/services/proxy/pkg/router/router_test.go @@ -10,8 +10,10 @@ import ( "testing" "github.com/owncloud/ocis/v2/ocis-pkg/log" + "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" "github.com/owncloud/ocis/v2/services/proxy/pkg/config/defaults" + "go-micro.dev/v4/selector" ) type matchertest struct { @@ -69,7 +71,9 @@ func TestQueryRouteMatcher(t *testing.T) { func TestRegexRouteMatcher(t *testing.T) { cfg := defaults.DefaultConfig() cfg.Policies = defaults.DefaultPolicies() - rt := New(cfg.PolicySelector, cfg.Policies, log.NewLogger()) + reg := registry.GetRegistry() + sel := selector.NewSelector(selector.Registry(reg)) + rt := New(sel, cfg.PolicySelector, cfg.Policies, log.NewLogger()) table := []matchertest{ {endpoint: ".*some\\/url.*parameter=true", target: "/foobar/baz/some/url?parameter=true", matches: true}, @@ -112,7 +116,7 @@ func TestRouter(t *testing.T) { })) defer svr.Close() - selector := &config.PolicySelector{ + policySelectorCfg := &config.PolicySelector{ Static: &config.StaticSelectorConf{ Policy: "default", }, @@ -129,7 +133,9 @@ func TestRouter(t *testing.T) { }, } - router := New(selector, policies, log.NewLogger()) + reg := registry.GetRegistry() + sel := selector.NewSelector(selector.Registry(reg)) + router := New(sel, policySelectorCfg, policies, log.NewLogger()) table := []matchertest{ {method: "PROPFIND", endpoint: "/dav/files/demo/", target: "ocdav"}, From 6578d3640f76cfa81a4bb0ab9a618b7e0872976e Mon Sep 17 00:00:00 2001 From: jkoberg Date: Fri, 14 Jun 2024 10:17:44 +0200 Subject: [PATCH 04/23] fix(natsjskvregistry): encode keys Signed-off-by: jkoberg --- changelog/unreleased/natsjskv-registry-encoding.md | 5 +++++ ocis-pkg/natsjsregistry/registry.go | 1 + 2 files changed, 6 insertions(+) create mode 100644 changelog/unreleased/natsjskv-registry-encoding.md diff --git a/changelog/unreleased/natsjskv-registry-encoding.md b/changelog/unreleased/natsjskv-registry-encoding.md new file mode 100644 index 00000000000..ee3f825cf7b --- /dev/null +++ b/changelog/unreleased/natsjskv-registry-encoding.md @@ -0,0 +1,5 @@ +Bugfix: Encode Registry Keys + +Encode the keys of the natsjskv registry as they have always been. + +https://github.com/owncloud/ocis/pull/9385 diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 789b49607d4..6e216fd9dbe 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -157,6 +157,7 @@ func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { store.Database("service-registry"), store.Table("service-registry"), natsjskv.DefaultMemory(), + natsjskv.EncodeKeys(), } addr := []string{"127.0.0.1:9233"} From 2fdf34fb4c75e6052d532da9312d3c7212091e3a Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 16 Jul 2024 12:19:48 +0200 Subject: [PATCH 05/23] fix(natsjsregistry): spread load evenly among instances Signed-off-by: jkoberg --- changelog/unreleased/fix-natsjskv-registry.md | 5 ++ ocis-pkg/natsjsregistry/registry.go | 82 ++++++++++++------- ocis-pkg/natsjsregistry/watcher.go | 74 +++++++++++++++++ 3 files changed, 130 insertions(+), 31 deletions(-) create mode 100644 changelog/unreleased/fix-natsjskv-registry.md create mode 100644 ocis-pkg/natsjsregistry/watcher.go diff --git a/changelog/unreleased/fix-natsjskv-registry.md b/changelog/unreleased/fix-natsjskv-registry.md new file mode 100644 index 00000000000..934f8f3b0e9 --- /dev/null +++ b/changelog/unreleased/fix-natsjskv-registry.md @@ -0,0 +1,5 @@ +Fix: Repair nats-js-kv registry + +The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it. + +https://github.com/owncloud/ocis/pull/9618 diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 6e216fd9dbe..5a45fe52bab 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -12,6 +12,7 @@ import ( "time" natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" + "github.com/google/uuid" "github.com/nats-io/nats.go" "go-micro.dev/v4/registry" "go-micro.dev/v4/store" @@ -23,6 +24,8 @@ var ( _registryAddressEnv = "MICRO_REGISTRY_ADDRESS" _registryUsernameEnv = "MICRO_REGISTRY_AUTH_USERNAME" _registryPasswordEnv = "MICRO_REGISTRY_AUTH_PASSWORD" + + _serviceDelimiter = "/" ) func init() { @@ -80,76 +83,93 @@ func (n *storeregistry) Register(s *registry.Service, _ ...registry.RegisterOpti if s == nil { return errors.New("wont store nil service") } + + unique := uuid.New().String() + if s.Metadata == nil { + s.Metadata = make(map[string]string) + } + s.Metadata["uuid"] = unique + b, err := json.Marshal(s) if err != nil { return err } return n.store.Write(&store.Record{ - Key: s.Name, + Key: s.Name + _serviceDelimiter + unique, Value: b, Expiry: n.expiry, }) } -// Deregister removes a service from the registry +// Deregister removes a service from the registry. func (n *storeregistry) Deregister(s *registry.Service, _ ...registry.DeregisterOption) error { n.lock.RLock() defer n.lock.RUnlock() - return n.store.Delete(s.Name) + var unique string + if s.Metadata != nil { + unique = s.Metadata["uuid"] + } + + return n.store.Delete(s.Name + _serviceDelimiter + unique) } // GetService gets a specific service from the registry func (n *storeregistry) GetService(s string, _ ...registry.GetOption) ([]*registry.Service, error) { - n.lock.RLock() - defer n.lock.RUnlock() - - recs, err := n.store.Read(s) - if err != nil { - return nil, err - } - svcs := make([]*registry.Service, 0, len(recs)) - for _, rec := range recs { - var s registry.Service - if err := json.Unmarshal(rec.Value, &s); err != nil { - return nil, err - } - svcs = append(svcs, &s) - } - return svcs, nil + // avoid listing e.g. `webfinger` when requesting `web` by adding the delimiter to the service name + return n.listServices(store.ListPrefix(s + _serviceDelimiter)) } // ListServices lists all registered services func (n *storeregistry) ListServices(...registry.ListOption) ([]*registry.Service, error) { + return n.listServices() +} + +// Watch allowes following the changes in the registry if it would be implemented +func (n *storeregistry) Watch(...registry.WatchOption) (registry.Watcher, error) { + return NewWatcher(n) +} + +// String returns the name of the registry +func (n *storeregistry) String() string { + return n.typ +} + +func (n *storeregistry) listServices(opts ...store.ListOption) ([]*registry.Service, error) { n.lock.RLock() defer n.lock.RUnlock() - keys, err := n.store.List() + keys, err := n.store.List(opts...) if err != nil { return nil, err } - var svcs []*registry.Service + svcs := make([]*registry.Service, 0, len(keys)) for _, k := range keys { - s, err := n.GetService(k) + s, err := n.getService(k) if err != nil { // TODO: continue ? return nil, err } - svcs = append(svcs, s...) + svcs = append(svcs, s) } return svcs, nil } -// Watch allowes following the changes in the registry if it would be implemented -func (n *storeregistry) Watch(...registry.WatchOption) (registry.Watcher, error) { - return nil, errors.New("watcher not implemented") -} - -// String returns the name of the registry -func (n *storeregistry) String() string { - return n.typ +func (n *storeregistry) getService(s string) (*registry.Service, error) { + recs, err := n.store.Read(s) + if err != nil { + return nil, err + } + if len(recs) == 0 { + return nil, registry.ErrNotFound + } + var svc registry.Service + if err := json.Unmarshal(recs[0].Value, &svc); err != nil { + return nil, err + } + return &svc, nil } func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { diff --git a/ocis-pkg/natsjsregistry/watcher.go b/ocis-pkg/natsjsregistry/watcher.go new file mode 100644 index 00000000000..83d094bca46 --- /dev/null +++ b/ocis-pkg/natsjsregistry/watcher.go @@ -0,0 +1,74 @@ +package natsjsregistry + +import ( + "errors" + + "github.com/nats-io/nats.go" + "go-micro.dev/v4/registry" +) + +// NatsWatcher is the watcher of the nats interface +type NatsWatcher interface { + Watch(bucket string) (nats.KeyWatcher, error) +} + +// Watcher is used to keep track of changes in the registry +type Watcher struct { + watch nats.KeyWatcher + updates <-chan nats.KeyValueEntry + reg *storeregistry +} + +// NewWatcher returns a new watcher +func NewWatcher(s *storeregistry) (*Watcher, error) { + w, ok := s.store.(NatsWatcher) + if !ok { + return nil, errors.New("store does not implement watcher interface") + } + + watcher, err := w.Watch("service-registry") + if err != nil { + return nil, err + } + + return &Watcher{ + watch: watcher, + updates: watcher.Updates(), + reg: s, + }, nil +} + +// Next returns the next result. It is a blocking call +func (w *Watcher) Next() (*registry.Result, error) { + kve := <-w.updates + if kve == nil { + return nil, errors.New("watcher stopped") + } + + service, err := w.reg.getService(kve.Key()) + if err != nil { + return nil, err + } + + var action string + switch kve.Operation() { + default: + action = "create" + case nats.KeyValuePut: + action = "create" + case nats.KeyValueDelete: + action = "delete" + case nats.KeyValuePurge: + action = "delete" + } + + return ®istry.Result{ + Service: service, + Action: action, + }, nil +} + +// Stop stops the watcher +func (w *Watcher) Stop() { + _ = w.watch.Stop() +} From 96762403fa8c9004044ea049aff513ec14525cc8 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Fri, 19 Jul 2024 11:33:26 +0200 Subject: [PATCH 06/23] fix(registry): Fix TTL and registration interval Signed-off-by: jkoberg --- changelog/unreleased/fix-natsjskv-registry.md | 3 +- ocis-pkg/natsjsregistry/registry.go | 4 +++ ocis-pkg/registry/expiry.go | 33 +++++++++++++++++++ ocis-pkg/registry/registry.go | 14 +++++--- ocis-pkg/service/grpc/service.go | 5 ++- ocis-pkg/service/http/service.go | 5 ++- 6 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 ocis-pkg/registry/expiry.go diff --git a/changelog/unreleased/fix-natsjskv-registry.md b/changelog/unreleased/fix-natsjskv-registry.md index 934f8f3b0e9..189de5b3ee5 100644 --- a/changelog/unreleased/fix-natsjskv-registry.md +++ b/changelog/unreleased/fix-natsjskv-registry.md @@ -2,4 +2,5 @@ Fix: Repair nats-js-kv registry The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it. -https://github.com/owncloud/ocis/pull/9618 +https://github.com/owncloud/ocis/pull/9654 +https://github.com/owncloud/ocis/pull/9620 diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 5a45fe52bab..97094d757d3 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -180,6 +180,10 @@ func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { natsjskv.EncodeKeys(), } + if ttl, ok := opts.Context.Value(expiryKey{}).(time.Duration); ok { + storeoptions = append(storeoptions, natsjskv.DefaultTTL(ttl)) + } + addr := []string{"127.0.0.1:9233"} if len(opts.Addrs) > 0 { addr = opts.Addrs diff --git a/ocis-pkg/registry/expiry.go b/ocis-pkg/registry/expiry.go new file mode 100644 index 00000000000..0eb1c02123f --- /dev/null +++ b/ocis-pkg/registry/expiry.go @@ -0,0 +1,33 @@ +package registry + +import ( + "os" + "time" +) + +const ( + _registryRegisterIntervalEnv = "EXPERIMENTAL_REGISTER_INTERVAL" + _registryRegisterTTLEnv = "EXPERIMENTAL_REGISTER_TTL" + + // Note: _defaultRegisterInterval should always be lower than _defaultRegisterTTL + _defaultRegisterInterval = time.Second * 25 + _defaultRegisterTTL = time.Second * 30 +) + +// GetRegisterInterval returns the register interval from the environment. +func GetRegisterInterval() time.Duration { + d, err := time.ParseDuration(os.Getenv(_registryRegisterIntervalEnv)) + if err != nil { + return _defaultRegisterInterval + } + return d +} + +// GetRegisterTTL returns the register TTL from the environment. +func GetRegisterTTL() time.Duration { + d, err := time.ParseDuration(os.Getenv(_registryRegisterTTLEnv)) + if err != nil { + return _defaultRegisterTTL + } + return d +} diff --git a/ocis-pkg/registry/registry.go b/ocis-pkg/registry/registry.go index 1672a1a8e17..130b3d6305f 100644 --- a/ocis-pkg/registry/registry.go +++ b/ocis-pkg/registry/registry.go @@ -31,11 +31,12 @@ var ( // Config is the config for a registry type Config struct { - Type string `mapstructure:"type"` - Addresses []string `mapstructure:"addresses"` - Username string `mapstructure:"username"` - Password string `mapstructure:"password"` - DisableCache bool `mapstructure:"disable_cache"` + Type string `mapstructure:"type"` + Addresses []string `mapstructure:"addresses"` + Username string `mapstructure:"username"` + Password string `mapstructure:"password"` + DisableCache bool `mapstructure:"disable_cache"` + TTL time.Duration `mapstructure:"ttl"` } // Option allows configuring the registry @@ -62,6 +63,7 @@ func GetRegistry(opts ...Option) mRegistry.Registry { case "natsjs", "nats-js", "nats-js-kv": // for backwards compatibility - we will stick with one of those _reg = natsjsregistry.NewRegistry( mRegistry.Addrs(cfg.Addresses...), + natsjsregistry.ServiceExpiry(cfg.TTL), ) case "memory": _reg = memr.NewRegistry() @@ -119,6 +121,8 @@ func getEnvs(opts ...Option) *Config { cfg.Addresses = s } + cfg.TTL = GetRegisterTTL() + for _, o := range opts { o(cfg) } diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 5776c79957f..3364c2194b1 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -4,7 +4,6 @@ import ( "crypto/tls" "fmt" "strings" - "time" mgrpcs "github.com/go-micro/plugins/v4/server/grpc" "github.com/go-micro/plugins/v4/wrapper/monitoring/prometheus" @@ -59,8 +58,8 @@ func NewServiceWithClient(client client.Client, opts ...Option) (Service, error) micro.Version(sopts.Version), micro.Context(sopts.Context), micro.Registry(registry.GetRegistry()), - micro.RegisterTTL(time.Second * 30), - micro.RegisterInterval(time.Second * 10), + micro.RegisterTTL(registry.GetRegisterTTL()), + micro.RegisterInterval(registry.GetRegisterInterval()), micro.WrapHandler(prometheus.NewHandlerWrapper()), micro.WrapClient(mtracer.NewClientWrapper( mtracer.WithTraceProvider(sopts.TraceProvider), diff --git a/ocis-pkg/service/http/service.go b/ocis-pkg/service/http/service.go index 8f4f6699421..cc37ace2b85 100644 --- a/ocis-pkg/service/http/service.go +++ b/ocis-pkg/service/http/service.go @@ -4,7 +4,6 @@ import ( "crypto/tls" "fmt" "strings" - "time" "github.com/owncloud/ocis/v2/ocis-pkg/broker" "github.com/owncloud/ocis/v2/ocis-pkg/registry" @@ -65,8 +64,8 @@ func NewService(opts ...Option) (Service, error) { micro.Context(sopts.Context), micro.Flags(sopts.Flags...), micro.Registry(registry.GetRegistry()), - micro.RegisterTTL(time.Second * 30), - micro.RegisterInterval(time.Second * 10), + micro.RegisterTTL(registry.GetRegisterTTL()), + micro.RegisterInterval(registry.GetRegisterInterval()), micro.WrapClient(mtracer.NewClientWrapper( mtracer.WithTraceProvider(sopts.TraceProvider), )), From c2e6b07a5a9a08d8eedc32b78da5eaf3a05e3ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 19 Jul 2024 12:37:08 +0200 Subject: [PATCH 07/23] naming is hard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis-pkg/natsjsregistry/options.go | 8 ++++---- ocis-pkg/natsjsregistry/registry.go | 32 +++++++++++++++++------------ ocis-pkg/registry/registry.go | 6 +++--- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/ocis-pkg/natsjsregistry/options.go b/ocis-pkg/natsjsregistry/options.go index dfcda616a59..533d0bd871b 100644 --- a/ocis-pkg/natsjsregistry/options.go +++ b/ocis-pkg/natsjsregistry/options.go @@ -9,7 +9,7 @@ import ( ) type storeOptionsKey struct{} -type expiryKey struct{} +type defaultTTLKey struct{} // StoreOptions sets the options for the underlying store func StoreOptions(opts []store.Option) registry.Option { @@ -21,12 +21,12 @@ func StoreOptions(opts []store.Option) registry.Option { } } -// ServiceExpiry allows setting an expiry time for service registrations -func ServiceExpiry(t time.Duration) registry.Option { +// DefaultTTL allows setting a default register TTL for services +func DefaultTTL(t time.Duration) registry.Option { return func(o *registry.Options) { if o.Context == nil { o.Context = context.Background() } - o.Context = context.WithValue(o.Context, expiryKey{}, t) + o.Context = context.WithValue(o.Context, defaultTTLKey{}, t) } } diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 97094d757d3..d9dcd5f9321 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -40,22 +40,22 @@ func NewRegistry(opts ...registry.Option) registry.Registry { for _, o := range opts { o(&options) } - exp, _ := options.Context.Value(expiryKey{}).(time.Duration) + defaultTTL, _ := options.Context.Value(defaultTTLKey{}).(time.Duration) n := &storeregistry{ - opts: options, - typ: _registryName, - expiry: exp, + opts: options, + typ: _registryName, + defaultTTL: defaultTTL, } n.store = natsjskv.NewStore(n.storeOptions(options)...) return n } type storeregistry struct { - opts registry.Options - store store.Store - typ string - expiry time.Duration - lock sync.RWMutex + opts registry.Options + store store.Store + typ string + defaultTTL time.Duration + lock sync.RWMutex } // Init inits the registry @@ -76,7 +76,7 @@ func (n *storeregistry) Options() registry.Options { } // Register adds a service to the registry -func (n *storeregistry) Register(s *registry.Service, _ ...registry.RegisterOption) error { +func (n *storeregistry) Register(s *registry.Service, opts ...registry.RegisterOption) error { n.lock.RLock() defer n.lock.RUnlock() @@ -84,6 +84,12 @@ func (n *storeregistry) Register(s *registry.Service, _ ...registry.RegisterOpti return errors.New("wont store nil service") } + var options registry.RegisterOptions + options.TTL = n.defaultTTL + for _, o := range opts { + o(&options) + } + unique := uuid.New().String() if s.Metadata == nil { s.Metadata = make(map[string]string) @@ -97,7 +103,7 @@ func (n *storeregistry) Register(s *registry.Service, _ ...registry.RegisterOpti return n.store.Write(&store.Record{ Key: s.Name + _serviceDelimiter + unique, Value: b, - Expiry: n.expiry, + Expiry: options.TTL, }) } @@ -180,8 +186,8 @@ func (n *storeregistry) storeOptions(opts registry.Options) []store.Option { natsjskv.EncodeKeys(), } - if ttl, ok := opts.Context.Value(expiryKey{}).(time.Duration); ok { - storeoptions = append(storeoptions, natsjskv.DefaultTTL(ttl)) + if defaultTTL, ok := opts.Context.Value(defaultTTLKey{}).(time.Duration); ok { + storeoptions = append(storeoptions, natsjskv.DefaultTTL(defaultTTL)) } addr := []string{"127.0.0.1:9233"} diff --git a/ocis-pkg/registry/registry.go b/ocis-pkg/registry/registry.go index 130b3d6305f..d8df986ad77 100644 --- a/ocis-pkg/registry/registry.go +++ b/ocis-pkg/registry/registry.go @@ -36,7 +36,7 @@ type Config struct { Username string `mapstructure:"username"` Password string `mapstructure:"password"` DisableCache bool `mapstructure:"disable_cache"` - TTL time.Duration `mapstructure:"ttl"` + RegisterTTL time.Duration `mapstructure:"register_ttl"` } // Option allows configuring the registry @@ -63,7 +63,7 @@ func GetRegistry(opts ...Option) mRegistry.Registry { case "natsjs", "nats-js", "nats-js-kv": // for backwards compatibility - we will stick with one of those _reg = natsjsregistry.NewRegistry( mRegistry.Addrs(cfg.Addresses...), - natsjsregistry.ServiceExpiry(cfg.TTL), + natsjsregistry.DefaultTTL(cfg.RegisterTTL), ) case "memory": _reg = memr.NewRegistry() @@ -121,7 +121,7 @@ func getEnvs(opts ...Option) *Config { cfg.Addresses = s } - cfg.TTL = GetRegisterTTL() + cfg.RegisterTTL = GetRegisterTTL() for _, o := range opts { o(cfg) From 712534aa0dce45be90e8a516ac7f88db4d7a3063 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 24 Jul 2024 12:22:15 +0200 Subject: [PATCH 08/23] feat(natsjsregistry): fix watcher feature Signed-off-by: jkoberg --- ocis-pkg/natsjsregistry/watcher.go | 36 +++++++++++------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/ocis-pkg/natsjsregistry/watcher.go b/ocis-pkg/natsjsregistry/watcher.go index 83d094bca46..0dc59f48db9 100644 --- a/ocis-pkg/natsjsregistry/watcher.go +++ b/ocis-pkg/natsjsregistry/watcher.go @@ -1,21 +1,23 @@ package natsjsregistry import ( + "encoding/json" "errors" + natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" "github.com/nats-io/nats.go" "go-micro.dev/v4/registry" ) // NatsWatcher is the watcher of the nats interface type NatsWatcher interface { - Watch(bucket string) (nats.KeyWatcher, error) + WatchAll(bucket string, opts ...nats.WatchOpt) (<-chan *natsjskv.StoreUpdate, func() error, error) } // Watcher is used to keep track of changes in the registry type Watcher struct { - watch nats.KeyWatcher - updates <-chan nats.KeyValueEntry + updates <-chan *natsjskv.StoreUpdate + stop func() error reg *storeregistry } @@ -26,14 +28,14 @@ func NewWatcher(s *storeregistry) (*Watcher, error) { return nil, errors.New("store does not implement watcher interface") } - watcher, err := w.Watch("service-registry") + watcher, stop, err := w.WatchAll("service-registry") if err != nil { return nil, err } return &Watcher{ - watch: watcher, - updates: watcher.Updates(), + updates: watcher, + stop: stop, reg: s, }, nil } @@ -45,30 +47,18 @@ func (w *Watcher) Next() (*registry.Result, error) { return nil, errors.New("watcher stopped") } - service, err := w.reg.getService(kve.Key()) - if err != nil { + var svc *registry.Service + if err := json.Unmarshal(kve.Value.Data, svc); err != nil { return nil, err } - var action string - switch kve.Operation() { - default: - action = "create" - case nats.KeyValuePut: - action = "create" - case nats.KeyValueDelete: - action = "delete" - case nats.KeyValuePurge: - action = "delete" - } - return ®istry.Result{ - Service: service, - Action: action, + Service: svc, + Action: kve.Action, }, nil } // Stop stops the watcher func (w *Watcher) Stop() { - _ = w.watch.Stop() + _ = w.stop() } From 39cc12e71f836f944162f027664d10e31dd56b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 2 Aug 2024 13:00:46 +0200 Subject: [PATCH 09/23] fix unmarshaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-natsjskv-registry.md | 2 ++ ocis-pkg/natsjsregistry/watcher.go | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/changelog/unreleased/fix-natsjskv-registry.md b/changelog/unreleased/fix-natsjskv-registry.md index 189de5b3ee5..9bebd027846 100644 --- a/changelog/unreleased/fix-natsjskv-registry.md +++ b/changelog/unreleased/fix-natsjskv-registry.md @@ -2,5 +2,7 @@ Fix: Repair nats-js-kv registry The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it. +https://github.com/owncloud/ocis/pull/9726 +https://github.com/owncloud/ocis/pull/9656 https://github.com/owncloud/ocis/pull/9654 https://github.com/owncloud/ocis/pull/9620 diff --git a/ocis-pkg/natsjsregistry/watcher.go b/ocis-pkg/natsjsregistry/watcher.go index 0dc59f48db9..867d726261c 100644 --- a/ocis-pkg/natsjsregistry/watcher.go +++ b/ocis-pkg/natsjsregistry/watcher.go @@ -47,13 +47,14 @@ func (w *Watcher) Next() (*registry.Result, error) { return nil, errors.New("watcher stopped") } - var svc *registry.Service - if err := json.Unmarshal(kve.Value.Data, svc); err != nil { + var svc registry.Service + if err := json.Unmarshal(kve.Value.Data, &svc); err != nil { + _ = w.stop() return nil, err } return ®istry.Result{ - Service: svc, + Service: &svc, Action: kve.Action, }, nil } From b99571c9e7eaf325c41799d670ffd94fccb1635a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 19 Jul 2024 15:18:45 +0200 Subject: [PATCH 10/23] reuse default node id when registering services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-natsjskv-registry.md | 1 + ocis-pkg/natsjsregistry/registry.go | 20 ++++--------------- ocis-pkg/registry/service.go | 9 +++++---- ocis-pkg/service/grpc/service.go | 1 + services/app-provider/pkg/command/server.go | 2 +- services/app-registry/pkg/command/server.go | 2 +- services/auth-basic/pkg/command/server.go | 2 +- services/auth-bearer/pkg/command/server.go | 2 +- services/auth-machine/pkg/command/server.go | 2 +- services/auth-service/pkg/command/server.go | 2 +- services/frontend/pkg/command/server.go | 2 +- services/gateway/pkg/command/server.go | 2 +- .../graph/pkg/service/v0/graph_suite_test.go | 2 +- services/groups/pkg/command/server.go | 2 +- .../pkg/service/notification_suite_test.go | 2 +- services/ocm/pkg/command/server.go | 4 ++-- .../search/pkg/search/search_suite_test.go | 2 +- services/sharing/pkg/command/server.go | 2 +- .../storage-publiclink/pkg/command/server.go | 2 +- services/storage-shares/pkg/command/server.go | 2 +- services/storage-system/pkg/command/server.go | 4 ++-- services/storage-users/pkg/command/server.go | 2 +- .../storage-users/pkg/task/task_suite_test.go | 2 +- .../userlog/pkg/service/service_suit_test.go | 2 +- services/users/pkg/command/server.go | 2 +- 25 files changed, 34 insertions(+), 43 deletions(-) diff --git a/changelog/unreleased/fix-natsjskv-registry.md b/changelog/unreleased/fix-natsjskv-registry.md index 9bebd027846..86dd84e15d0 100644 --- a/changelog/unreleased/fix-natsjskv-registry.md +++ b/changelog/unreleased/fix-natsjskv-registry.md @@ -3,6 +3,7 @@ Fix: Repair nats-js-kv registry The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it. https://github.com/owncloud/ocis/pull/9726 +https://github.com/owncloud/ocis/pull/9662 https://github.com/owncloud/ocis/pull/9656 https://github.com/owncloud/ocis/pull/9654 https://github.com/owncloud/ocis/pull/9620 diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index d9dcd5f9321..b66896f168b 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -12,9 +12,9 @@ import ( "time" natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" - "github.com/google/uuid" "github.com/nats-io/nats.go" "go-micro.dev/v4/registry" + "go-micro.dev/v4/server" "go-micro.dev/v4/store" "go-micro.dev/v4/util/cmd" ) @@ -25,7 +25,7 @@ var ( _registryUsernameEnv = "MICRO_REGISTRY_AUTH_USERNAME" _registryPasswordEnv = "MICRO_REGISTRY_AUTH_PASSWORD" - _serviceDelimiter = "/" + _serviceDelimiter = "@" ) func init() { @@ -90,18 +90,12 @@ func (n *storeregistry) Register(s *registry.Service, opts ...registry.RegisterO o(&options) } - unique := uuid.New().String() - if s.Metadata == nil { - s.Metadata = make(map[string]string) - } - s.Metadata["uuid"] = unique - b, err := json.Marshal(s) if err != nil { return err } return n.store.Write(&store.Record{ - Key: s.Name + _serviceDelimiter + unique, + Key: s.Name + _serviceDelimiter + server.DefaultId, Value: b, Expiry: options.TTL, }) @@ -111,13 +105,7 @@ func (n *storeregistry) Register(s *registry.Service, opts ...registry.RegisterO func (n *storeregistry) Deregister(s *registry.Service, _ ...registry.DeregisterOption) error { n.lock.RLock() defer n.lock.RUnlock() - - var unique string - if s.Metadata != nil { - unique = s.Metadata["uuid"] - } - - return n.store.Delete(s.Name + _serviceDelimiter + unique) + return n.store.Delete(s.Name + _serviceDelimiter + server.DefaultId) } // GetService gets a specific service from the registry diff --git a/ocis-pkg/registry/service.go b/ocis-pkg/registry/service.go index da80a891223..65c62e8d262 100644 --- a/ocis-pkg/registry/service.go +++ b/ocis-pkg/registry/service.go @@ -7,10 +7,11 @@ import ( "strings" mRegistry "go-micro.dev/v4/registry" + "go-micro.dev/v4/server" "go-micro.dev/v4/util/addr" ) -func BuildGRPCService(serviceID, uuid, address string, version string) *mRegistry.Service { +func BuildGRPCService(serviceID, address string, version string) *mRegistry.Service { var host string var port int @@ -28,7 +29,7 @@ func BuildGRPCService(serviceID, uuid, address string, version string) *mRegistr } node := &mRegistry.Node{ - Id: serviceID + "-" + uuid, + Id: serviceID + "-" + server.DefaultId, Address: net.JoinHostPort(addr, fmt.Sprint(port)), Metadata: make(map[string]string), } @@ -46,7 +47,7 @@ func BuildGRPCService(serviceID, uuid, address string, version string) *mRegistr } } -func BuildHTTPService(serviceID, uuid, address string, version string) *mRegistry.Service { +func BuildHTTPService(serviceID, address string, version string) *mRegistry.Service { var host string var port int @@ -64,7 +65,7 @@ func BuildHTTPService(serviceID, uuid, address string, version string) *mRegistr } node := &mRegistry.Node{ - Id: serviceID + "-" + uuid, + Id: serviceID + "-" + server.DefaultId, Address: net.JoinHostPort(addr, fmt.Sprint(port)), Metadata: make(map[string]string), } diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 3364c2194b1..6afe731e2f8 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -25,6 +25,7 @@ func NewServiceWithClient(client client.Client, opts ...Option) (Service, error) var mServer server.Server sopts := newOptions(opts...) tlsConfig := &tls.Config{} + if sopts.TLSEnabled { var cert tls.Certificate var err error diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 6259e7b8498..35ec85888a7 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 54bf5241035..d540c4a5be7 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -77,7 +77,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index d7e9f8dffbc..e39e493f1c2 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 5646f639914..0fa78ee0db3 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index e19fb45f69b..2e27fceb425 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 565f6757476..ad28f3c79dc 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -83,7 +83,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index a60e81153dc..f7e6f9d7bd2 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -86,7 +86,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.HTTP.Addr, version.GetString()) + httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) if err := registry.RegisterService(ctx, httpSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index ebbc7f7eb4a..d34b1a99866 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -77,7 +77,7 @@ func Server(cfg *config.Config) *cli.Command { cancel() }) - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/graph/pkg/service/v0/graph_suite_test.go b/services/graph/pkg/service/v0/graph_suite_test.go index 70dfcce1450..8446bc9b690 100644 --- a/services/graph/pkg/service/v0/graph_suite_test.go +++ b/services/graph/pkg/service/v0/graph_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 6690ebbb118..69b7215d0f1 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/notifications/pkg/service/notification_suite_test.go b/services/notifications/pkg/service/notification_suite_test.go index 7f282054fb6..e045e439814 100644 --- a/services/notifications/pkg/service/notification_suite_test.go +++ b/services/notifications/pkg/service/notification_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 1025d1ce735..43a2b7cdecb 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -83,12 +83,12 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.HTTP.Addr, version.GetString()) + httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) if err := registry.RegisterService(ctx, httpSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/search/pkg/search/search_suite_test.go b/services/search/pkg/search/search_suite_test.go index 9422179fc53..ace85d9294c 100644 --- a/services/search/pkg/search/search_suite_test.go +++ b/services/search/pkg/search/search_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 61f72d65c53..108c8510a70 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -99,7 +99,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 18da72cee52..67664bcc3d5 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index 8af5b1fa383..e615fc2818a 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -82,7 +82,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 00618bb9a88..0064135ae88 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -82,12 +82,12 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - httpScv := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.HTTP.Addr, version.GetString()) + httpScv := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) if err := registry.RegisterService(ctx, httpScv, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the http service") } diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index 3cf533cce1a..da5feee7065 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } diff --git a/services/storage-users/pkg/task/task_suite_test.go b/services/storage-users/pkg/task/task_suite_test.go index ac0c8a44b9d..38372778085 100644 --- a/services/storage-users/pkg/task/task_suite_test.go +++ b/services/storage-users/pkg/task/task_suite_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/userlog/pkg/service/service_suit_test.go b/services/userlog/pkg/service/service_suit_test.go index 9da9654d4e9..d049672b76a 100644 --- a/services/userlog/pkg/service/service_suit_test.go +++ b/services/userlog/pkg/service/service_suit_test.go @@ -12,7 +12,7 @@ import ( func init() { r := registry.GetRegistry(registry.Inmemory()) - service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "", "") + service := registry.BuildGRPCService("com.owncloud.api.gateway", "", "") service.Nodes = []*mRegistry.Node{{ Address: "any", }} diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index d5894fbb5a2..823f60812b4 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -95,7 +95,7 @@ func Server(cfg *config.Config) *cli.Command { sync.Trap(&gr, cancel) } - grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) + grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } From 921e5e18ab03cde7fc439ea1e6ed7a932056b995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 6 Aug 2024 12:38:10 +0200 Subject: [PATCH 11/23] add version to key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis-pkg/natsjsregistry/registry.go | 4 ++-- ocis-pkg/natsjsregistry/watcher.go | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index b66896f168b..1f5c3036ce0 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -95,7 +95,7 @@ func (n *storeregistry) Register(s *registry.Service, opts ...registry.RegisterO return err } return n.store.Write(&store.Record{ - Key: s.Name + _serviceDelimiter + server.DefaultId, + Key: s.Name + _serviceDelimiter + server.DefaultId + _serviceDelimiter + s.Version, Value: b, Expiry: options.TTL, }) @@ -105,7 +105,7 @@ func (n *storeregistry) Register(s *registry.Service, opts ...registry.RegisterO func (n *storeregistry) Deregister(s *registry.Service, _ ...registry.DeregisterOption) error { n.lock.RLock() defer n.lock.RUnlock() - return n.store.Delete(s.Name + _serviceDelimiter + server.DefaultId) + return n.store.Delete(s.Name + _serviceDelimiter + server.DefaultId + _serviceDelimiter + s.Version) } // GetService gets a specific service from the registry diff --git a/ocis-pkg/natsjsregistry/watcher.go b/ocis-pkg/natsjsregistry/watcher.go index 867d726261c..8ca81b2bf22 100644 --- a/ocis-pkg/natsjsregistry/watcher.go +++ b/ocis-pkg/natsjsregistry/watcher.go @@ -3,6 +3,7 @@ package natsjsregistry import ( "encoding/json" "errors" + "strings" natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" "github.com/nats-io/nats.go" @@ -48,9 +49,21 @@ func (w *Watcher) Next() (*registry.Result, error) { } var svc registry.Service - if err := json.Unmarshal(kve.Value.Data, &svc); err != nil { - _ = w.stop() - return nil, err + if kve.Value.Data == nil { + // fake a service + parts := strings.SplitN(kve.Value.Key, _serviceDelimiter, 3) + if len(parts) != 3 { + return nil, errors.New("invalid service key") + } + svc.Name = parts[0] + // ocis registers nodes with a - seperator + svc.Nodes = []*registry.Node{{Id: parts[0] + "-" + parts[1]}} + svc.Version = parts[2] + } else { + if err := json.Unmarshal(kve.Value.Data, &svc); err != nil { + _ = w.stop() + return nil, err + } } return ®istry.Result{ From bac5ec7f38e2eb89e8dc3b7ef7f66c309aac4556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 6 Aug 2024 12:38:50 +0200 Subject: [PATCH 12/23] aggregate services by versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis-pkg/natsjsregistry/registry.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ocis-pkg/natsjsregistry/registry.go b/ocis-pkg/natsjsregistry/registry.go index 1f5c3036ce0..78cc3b1b543 100644 --- a/ocis-pkg/natsjsregistry/registry.go +++ b/ocis-pkg/natsjsregistry/registry.go @@ -138,20 +138,28 @@ func (n *storeregistry) listServices(opts ...store.ListOption) ([]*registry.Serv return nil, err } - svcs := make([]*registry.Service, 0, len(keys)) + versions := map[string]*registry.Service{} for _, k := range keys { - s, err := n.getService(k) + s, err := n.getNode(k) if err != nil { // TODO: continue ? return nil, err } + if versions[s.Version] == nil { + versions[s.Version] = s + } else { + versions[s.Version].Nodes = append(versions[s.Version].Nodes, s.Nodes...) + } + } + svcs := make([]*registry.Service, 0, len(versions)) + for _, s := range versions { svcs = append(svcs, s) - } return svcs, nil } -func (n *storeregistry) getService(s string) (*registry.Service, error) { +// getNode retrieves a node from the store. It returns a service to also keep track of the version. +func (n *storeregistry) getNode(s string) (*registry.Service, error) { recs, err := n.store.Read(s) if err != nil { return nil, err From e393f3e4d9e04674bb0c3fbd234417366bd9015b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 6 Aug 2024 13:04:45 +0200 Subject: [PATCH 13/23] fix comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis-pkg/natsjsregistry/watcher.go | 2 +- ocis-pkg/registry/service.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ocis-pkg/natsjsregistry/watcher.go b/ocis-pkg/natsjsregistry/watcher.go index 8ca81b2bf22..9376c5ae42f 100644 --- a/ocis-pkg/natsjsregistry/watcher.go +++ b/ocis-pkg/natsjsregistry/watcher.go @@ -56,7 +56,7 @@ func (w *Watcher) Next() (*registry.Result, error) { return nil, errors.New("invalid service key") } svc.Name = parts[0] - // ocis registers nodes with a - seperator + // ocis registers nodes with a - separator svc.Nodes = []*registry.Node{{Id: parts[0] + "-" + parts[1]}} svc.Version = parts[2] } else { diff --git a/ocis-pkg/registry/service.go b/ocis-pkg/registry/service.go index 65c62e8d262..aebccc75202 100644 --- a/ocis-pkg/registry/service.go +++ b/ocis-pkg/registry/service.go @@ -65,6 +65,7 @@ func BuildHTTPService(serviceID, address string, version string) *mRegistry.Serv } node := &mRegistry.Node{ + // This id is read by the registry watcher Id: serviceID + "-" + server.DefaultId, Address: net.JoinHostPort(addr, fmt.Sprint(port)), Metadata: make(map[string]string), From 4dfec72179d4f8b87ca6699db6a7fee2c74be032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 11 Sep 2024 11:47:40 +0200 Subject: [PATCH 14/23] vendor mod changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 2 +- go.sum | 4 +-- .../cs3org/reva/v2/pkg/micro/ocdav/option.go | 27 +++++++++++++++++++ .../cs3org/reva/v2/pkg/micro/ocdav/service.go | 6 ++--- .../cs3org/reva/v2/pkg/store/store.go | 1 + vendor/modules.txt | 3 +-- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 2617182b084..4448e9a28a2 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.9.0 github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 - github.com/cs3org/reva/v2 v2.19.8 + github.com/cs3org/reva/v2 v2.19.9 github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e github.com/egirna/icap-client v0.1.1 diff --git a/go.sum b/go.sum index d342fda3133..77320ad1e1d 100644 --- a/go.sum +++ b/go.sum @@ -1019,8 +1019,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c= github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME= github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 h1:BUdwkIlf8IS2FasrrPg8gGPHQPOrQ18MS1Oew2tmGtY= github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva/v2 v2.19.8 h1:MXmE2W3gh1UK1Dwj/jwQDEcSeYJBZOyDF2/D3BAcvDw= -github.com/cs3org/reva/v2 v2.19.8/go.mod h1:GRUrOp5HbFVwZTgR9bVrMZ/MvVy+Jhxw1PdMmhhKP9E= +github.com/cs3org/reva/v2 v2.19.9 h1:cdjByJRBVxD8gBAZRXcJJ6y5elCbodxuxiItyfjKuSE= +github.com/cs3org/reva/v2 v2.19.9/go.mod h1:9UKEB2IrqPOm2awixItp1G9Ax4VcdB0GSJNipCeVUuc= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= diff --git a/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/option.go b/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/option.go index 9d7ebdabe41..6e9693bf57e 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/option.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/option.go @@ -21,6 +21,7 @@ package ocdav import ( "context" "crypto/tls" + "time" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav" @@ -29,6 +30,7 @@ import ( "github.com/cs3org/reva/v2/pkg/storage/favorite" "github.com/rs/zerolog" "go-micro.dev/v4/broker" + "go-micro.dev/v4/registry" "go.opentelemetry.io/otel/trace" "google.golang.org/grpc/credentials" ) @@ -70,6 +72,10 @@ type Options struct { AllowedHeaders []string AllowedMethods []string AllowDepthInfinity bool + + RegisterTTL time.Duration + RegisterInterval time.Duration + Registry registry.Registry } // newOptions initializes the available default options. @@ -383,3 +389,24 @@ func ItemNameMaxLength(i int) Option { o.config.NameValidation.MaxLength = i } } + +// RegisterTTL provides a function to set the RegisterTTL option. +func RegisterTTL(ttl time.Duration) Option { + return func(o *Options) { + o.RegisterTTL = ttl + } +} + +// RegisterInterval provides a function to set the RegisterInterval option. +func RegisterInterval(interval time.Duration) Option { + return func(o *Options) { + o.RegisterInterval = interval + } +} + +// Registry provides a function to set the Registry option. +func Registry(registry registry.Registry) Option { + return func(o *Options) { + o.Registry = registry + } +} diff --git a/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/service.go b/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/service.go index 252288d5441..d9eb73fbfc0 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/service.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/micro/ocdav/service.go @@ -78,6 +78,9 @@ func Service(opts ...Option) (micro.Service, error) { server.Name(sopts.Name), server.Address(sopts.Address), // Address defaults to ":0" and will pick any free port server.Version(sopts.config.VersionString), + server.RegisterTTL(sopts.RegisterTTL), + server.RegisterInterval(sopts.RegisterInterval), + server.Registry(sopts.Registry), ) revaService, err := ocdav.NewWith(&sopts.config, sopts.FavoriteManager, sopts.lockSystem, &sopts.Logger, sopts.GatewaySelector) @@ -125,9 +128,6 @@ func Service(opts ...Option) (micro.Service, error) { micro.Registry(registry.GetRegistry()), ) - // Init the service? make that optional? - service.Init() - // finally, return the service so it can be Run() by the caller himself return service, nil } diff --git a/vendor/github.com/cs3org/reva/v2/pkg/store/store.go b/vendor/github.com/cs3org/reva/v2/pkg/store/store.go index 0038d00580b..b18d3f5de82 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/store/store.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/store/store.go @@ -152,6 +152,7 @@ func Create(opts ...microstore.Option) microstore.Store { return natsjskv.NewStore( append(opts, natsjskv.NatsOptions(natsOptions), // always pass in properly initialized default nats options + natsjskv.EncodeKeys(), natsjskv.DefaultTTL(ttl))..., ) case TypeMemory, "mem", "": // allow existing short form and use as default diff --git a/vendor/modules.txt b/vendor/modules.txt index 46f553b4ec1..63ac6e92212 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -359,7 +359,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1 github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1 github.com/cs3org/go-cs3apis/cs3/tx/v1beta1 github.com/cs3org/go-cs3apis/cs3/types/v1beta1 -# github.com/cs3org/reva/v2 v2.19.8 +# github.com/cs3org/reva/v2 v2.19.9 ## explicit; go 1.21 github.com/cs3org/reva/v2/cmd/revad/internal/grace github.com/cs3org/reva/v2/cmd/revad/runtime @@ -1673,7 +1673,6 @@ github.com/rogpeppe/go-internal/internal/syscall/windows github.com/rogpeppe/go-internal/internal/syscall/windows/sysdll github.com/rogpeppe/go-internal/lockedfile github.com/rogpeppe/go-internal/lockedfile/internal/filelock -github.com/rogpeppe/go-internal/semver # github.com/rs/cors v1.10.1 ## explicit; go 1.13 github.com/rs/cors From 55aa5336c83d80eda82b904df1bfaa0a48e434bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 12:25:16 +0200 Subject: [PATCH 15/23] work on signals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis/pkg/command/root.go | 6 +++++- ocis/pkg/command/server.go | 2 +- ocis/pkg/runtime/runtime.go | 6 ++++-- ocis/pkg/runtime/service/service.go | 8 ++++---- services/gateway/cmd/gateway/main.go | 7 ++++++- services/gateway/pkg/command/root.go | 2 +- services/gateway/pkg/command/server.go | 21 +++++++-------------- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 2edf4a750f5..666ee0544f0 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -1,7 +1,10 @@ package command import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/ocis-pkg/clihelper" "github.com/owncloud/ocis/v2/ocis-pkg/config" @@ -25,5 +28,6 @@ func Execute() error { ) } - return app.Run(os.Args) + ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + return app.RunContext(ctx, os.Args) } diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 108038ce72d..f9c3aed0703 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -21,7 +21,7 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { // Prefer the in-memory registry as the default when running in single-binary mode r := runtime.New(cfg) - return r.Start() + return r.Start(c.Context) }, } } diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 32e6b8e1a91..49ce93c3b7e 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -1,6 +1,8 @@ package runtime import ( + "context" + "github.com/owncloud/ocis/v2/ocis-pkg/config" "github.com/owncloud/ocis/v2/ocis/pkg/runtime/service" ) @@ -18,6 +20,6 @@ func New(cfg *config.Config) Runtime { } // Start rpc runtime -func (r *Runtime) Start() error { - return service.Start(service.WithConfig(r.c)) +func (r *Runtime) Start(ctx context.Context) error { + return service.Start(ctx, service.WithConfig(r.c)) } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index 83d327f78e4..ce00289ce75 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -93,7 +93,7 @@ type Service struct { // calls are done explicitly to loadFromEnv(). // Since this is the public constructor, options need to be added, at the moment only logging options // are supported in order to match the running OwnCloud services structured log. -func NewService(options ...Option) (*Service, error) { +func NewService(ctx context.Context, options ...Option) (*Service, error) { opts := NewOptions() for _, f := range options { @@ -106,7 +106,7 @@ func NewService(options ...Option) (*Service, error) { log.Level(opts.Config.Log.Level), ) - globalCtx, cancelGlobal := context.WithCancel(context.Background()) + globalCtx, cancelGlobal := context.WithCancel(ctx) s := &Service{ Services: make([]serviceFuncMap, len(_waitFuncs)), @@ -339,12 +339,12 @@ func NewService(options ...Option) (*Service, error) { // Start a rpc service. By default, the package scope Start will run all default services to provide with a working // oCIS instance. -func Start(o ...Option) error { +func Start(ctx context.Context, o ...Option) error { // Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect // from the caller, the previous statement holds truth. // prepare a new rpc Service struct. - s, err := NewService(o...) + s, err := NewService(ctx, o...) if err != nil { return err } diff --git a/services/gateway/cmd/gateway/main.go b/services/gateway/cmd/gateway/main.go index d22e804011a..503e12de1c1 100644 --- a/services/gateway/cmd/gateway/main.go +++ b/services/gateway/cmd/gateway/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/gateway/pkg/command" "github.com/owncloud/ocis/v2/services/gateway/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/gateway/pkg/command/root.go b/services/gateway/pkg/command/root.go index fcf6db18db0..940a43259cf 100644 --- a/services/gateway/pkg/command/root.go +++ b/services/gateway/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index d34b1a99866..9f556d556e7 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -37,7 +37,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -51,7 +51,9 @@ func Server(cfg *config.Config) *cli.Command { runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - + logger.Info(). + Str("server", cfg.Service.Name). + Msg("reva runtime exited") return nil }, func(err error) { logger.Error(). @@ -60,7 +62,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( @@ -74,6 +75,9 @@ func Server(cfg *config.Config) *cli.Command { } gr.Add(debugServer.ListenAndServe, func(_ error) { + logger.Info(). + Str("server", cfg.Service.Name). + Msg("Shutting down debug erver") cancel() }) @@ -86,14 +90,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} From 410658bda4ab0e6ae64a545f0ad8445e9e8ad790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:26:50 +0200 Subject: [PATCH 16/23] NotifyContext when running services standalone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/antivirus/cmd/antivirus/main.go | 7 ++++++- services/app-provider/cmd/app-provider/main.go | 7 ++++++- services/app-registry/cmd/app-registry/main.go | 7 ++++++- services/audit/cmd/audit/main.go | 7 ++++++- services/auth-basic/cmd/auth-basic/main.go | 7 ++++++- services/auth-bearer/cmd/auth-bearer/main.go | 7 ++++++- services/auth-machine/cmd/auth-machine/main.go | 7 ++++++- services/auth-service/cmd/auth-service/main.go | 7 ++++++- services/clientlog/cmd/clientlog/main.go | 7 ++++++- services/eventhistory/cmd/eventhistory/main.go | 7 ++++++- services/frontend/cmd/frontend/main.go | 7 ++++++- services/graph/cmd/graph/main.go | 7 ++++++- services/groups/cmd/groups/main.go | 7 ++++++- services/idm/cmd/idm/main.go | 7 ++++++- services/idp/cmd/idp/main.go | 7 ++++++- services/invitations/cmd/invitations/main.go | 7 ++++++- services/nats/cmd/nats/main.go | 7 ++++++- services/notifications/cmd/notifications/main.go | 7 ++++++- services/ocdav/cmd/ocdav/main.go | 7 ++++++- services/ocm/cmd/ocm/main.go | 7 ++++++- services/ocs/cmd/ocs/main.go | 7 ++++++- services/policies/cmd/policies/main.go | 7 ++++++- services/postprocessing/cmd/postprocessing/main.go | 7 ++++++- services/proxy/cmd/proxy/main.go | 7 ++++++- services/search/cmd/search/main.go | 7 ++++++- services/settings/cmd/settings/main.go | 7 ++++++- services/sharing/cmd/sharing/main.go | 7 ++++++- services/sse/cmd/sse/main.go | 7 ++++++- services/storage-publiclink/cmd/storage-publiclink/main.go | 7 ++++++- services/storage-shares/cmd/storage-shares/main.go | 7 ++++++- services/storage-system/cmd/storage-system/main.go | 7 ++++++- services/storage-users/cmd/storage-users/main.go | 7 ++++++- services/store/cmd/store/main.go | 7 ++++++- services/thumbnails/cmd/thumbnails/main.go | 7 ++++++- services/userlog/cmd/userlog/main.go | 7 ++++++- services/users/cmd/user/main.go | 7 ++++++- services/web/cmd/web/main.go | 7 ++++++- services/webdav/cmd/webdav/main.go | 7 ++++++- services/webfinger/cmd/webfinger/main.go | 7 ++++++- 39 files changed, 234 insertions(+), 39 deletions(-) diff --git a/services/antivirus/cmd/antivirus/main.go b/services/antivirus/cmd/antivirus/main.go index b37a1ca3edf..174e6fe3fbc 100644 --- a/services/antivirus/cmd/antivirus/main.go +++ b/services/antivirus/cmd/antivirus/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/antivirus/pkg/command" "github.com/owncloud/ocis/v2/services/antivirus/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/app-provider/cmd/app-provider/main.go b/services/app-provider/cmd/app-provider/main.go index c4afd562c2d..42b66fd9c07 100644 --- a/services/app-provider/cmd/app-provider/main.go +++ b/services/app-provider/cmd/app-provider/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/app-provider/pkg/command" "github.com/owncloud/ocis/v2/services/app-provider/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/app-registry/cmd/app-registry/main.go b/services/app-registry/cmd/app-registry/main.go index 6a9d91f7d68..e00af3f2abc 100644 --- a/services/app-registry/cmd/app-registry/main.go +++ b/services/app-registry/cmd/app-registry/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/app-registry/pkg/command" "github.com/owncloud/ocis/v2/services/app-registry/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/audit/cmd/audit/main.go b/services/audit/cmd/audit/main.go index f365e874ec3..8b33880d6c8 100644 --- a/services/audit/cmd/audit/main.go +++ b/services/audit/cmd/audit/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/audit/pkg/command" "github.com/owncloud/ocis/v2/services/audit/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/auth-basic/cmd/auth-basic/main.go b/services/auth-basic/cmd/auth-basic/main.go index ec5af41edf3..784d715be54 100644 --- a/services/auth-basic/cmd/auth-basic/main.go +++ b/services/auth-basic/cmd/auth-basic/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/auth-basic/pkg/command" "github.com/owncloud/ocis/v2/services/auth-basic/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/auth-bearer/cmd/auth-bearer/main.go b/services/auth-bearer/cmd/auth-bearer/main.go index 8617701cfde..4bc12ab09c4 100644 --- a/services/auth-bearer/cmd/auth-bearer/main.go +++ b/services/auth-bearer/cmd/auth-bearer/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/command" "github.com/owncloud/ocis/v2/services/auth-bearer/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/auth-machine/cmd/auth-machine/main.go b/services/auth-machine/cmd/auth-machine/main.go index 937b0b20cdf..aeb79d5ccf0 100644 --- a/services/auth-machine/cmd/auth-machine/main.go +++ b/services/auth-machine/cmd/auth-machine/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/auth-machine/pkg/command" "github.com/owncloud/ocis/v2/services/auth-machine/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/auth-service/cmd/auth-service/main.go b/services/auth-service/cmd/auth-service/main.go index bcc7a625ec7..81ce1579e95 100644 --- a/services/auth-service/cmd/auth-service/main.go +++ b/services/auth-service/cmd/auth-service/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/auth-service/pkg/command" "github.com/owncloud/ocis/v2/services/auth-service/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/clientlog/cmd/clientlog/main.go b/services/clientlog/cmd/clientlog/main.go index ce0d4a4aff9..cdd91f273a3 100644 --- a/services/clientlog/cmd/clientlog/main.go +++ b/services/clientlog/cmd/clientlog/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/clientlog/pkg/command" "github.com/owncloud/ocis/v2/services/clientlog/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/eventhistory/cmd/eventhistory/main.go b/services/eventhistory/cmd/eventhistory/main.go index d2172949bc6..4a1d3f87016 100644 --- a/services/eventhistory/cmd/eventhistory/main.go +++ b/services/eventhistory/cmd/eventhistory/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/command" "github.com/owncloud/ocis/v2/services/eventhistory/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/frontend/cmd/frontend/main.go b/services/frontend/cmd/frontend/main.go index cbdc5dac510..8e12e7761aa 100644 --- a/services/frontend/cmd/frontend/main.go +++ b/services/frontend/cmd/frontend/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/frontend/pkg/command" "github.com/owncloud/ocis/v2/services/frontend/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/graph/cmd/graph/main.go b/services/graph/cmd/graph/main.go index 7844daa6af9..0775fcb4874 100644 --- a/services/graph/cmd/graph/main.go +++ b/services/graph/cmd/graph/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/graph/pkg/command" "github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/groups/cmd/groups/main.go b/services/groups/cmd/groups/main.go index 2172fc84505..d13447d4964 100644 --- a/services/groups/cmd/groups/main.go +++ b/services/groups/cmd/groups/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/groups/pkg/command" "github.com/owncloud/ocis/v2/services/groups/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/idm/cmd/idm/main.go b/services/idm/cmd/idm/main.go index f30202e587d..ab6af89f2bd 100644 --- a/services/idm/cmd/idm/main.go +++ b/services/idm/cmd/idm/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/idm/pkg/command" "github.com/owncloud/ocis/v2/services/idm/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/idp/cmd/idp/main.go b/services/idp/cmd/idp/main.go index 174283c909a..d3def5ab1c5 100644 --- a/services/idp/cmd/idp/main.go +++ b/services/idp/cmd/idp/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/idp/pkg/command" "github.com/owncloud/ocis/v2/services/idp/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/invitations/cmd/invitations/main.go b/services/invitations/cmd/invitations/main.go index 3290c0b3065..86da31fcb1c 100644 --- a/services/invitations/cmd/invitations/main.go +++ b/services/invitations/cmd/invitations/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/invitations/pkg/command" "github.com/owncloud/ocis/v2/services/invitations/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/nats/cmd/nats/main.go b/services/nats/cmd/nats/main.go index 4b5803ac78c..2e75edad3d2 100644 --- a/services/nats/cmd/nats/main.go +++ b/services/nats/cmd/nats/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/nats/pkg/command" "github.com/owncloud/ocis/v2/services/nats/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/notifications/cmd/notifications/main.go b/services/notifications/cmd/notifications/main.go index 5d5752af388..1836a24f857 100644 --- a/services/notifications/cmd/notifications/main.go +++ b/services/notifications/cmd/notifications/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/notifications/pkg/command" "github.com/owncloud/ocis/v2/services/notifications/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/ocdav/cmd/ocdav/main.go b/services/ocdav/cmd/ocdav/main.go index 9875027bdb5..964af1667ca 100644 --- a/services/ocdav/cmd/ocdav/main.go +++ b/services/ocdav/cmd/ocdav/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/ocdav/pkg/command" "github.com/owncloud/ocis/v2/services/ocdav/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/ocm/cmd/ocm/main.go b/services/ocm/cmd/ocm/main.go index 6ac3d5a5773..6a4b7926d8b 100644 --- a/services/ocm/cmd/ocm/main.go +++ b/services/ocm/cmd/ocm/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/ocm/pkg/command" "github.com/owncloud/ocis/v2/services/ocm/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/ocs/cmd/ocs/main.go b/services/ocs/cmd/ocs/main.go index a2b9021ead9..8ae7d026221 100644 --- a/services/ocs/cmd/ocs/main.go +++ b/services/ocs/cmd/ocs/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/ocs/pkg/command" "github.com/owncloud/ocis/v2/services/ocs/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/policies/cmd/policies/main.go b/services/policies/cmd/policies/main.go index db0896e4072..09abb5e85ed 100644 --- a/services/policies/cmd/policies/main.go +++ b/services/policies/cmd/policies/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/policies/pkg/command" "github.com/owncloud/ocis/v2/services/policies/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/postprocessing/cmd/postprocessing/main.go b/services/postprocessing/cmd/postprocessing/main.go index ddc191e3a39..e42d50ccdfe 100644 --- a/services/postprocessing/cmd/postprocessing/main.go +++ b/services/postprocessing/cmd/postprocessing/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/command" "github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/proxy/cmd/proxy/main.go b/services/proxy/cmd/proxy/main.go index 7db75b5de08..9c51a443e45 100644 --- a/services/proxy/cmd/proxy/main.go +++ b/services/proxy/cmd/proxy/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/proxy/pkg/command" "github.com/owncloud/ocis/v2/services/proxy/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/search/cmd/search/main.go b/services/search/cmd/search/main.go index 70103e7bf00..807b6642733 100644 --- a/services/search/cmd/search/main.go +++ b/services/search/cmd/search/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/search/pkg/command" "github.com/owncloud/ocis/v2/services/search/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/settings/cmd/settings/main.go b/services/settings/cmd/settings/main.go index 1e21338dd80..8833af4bbeb 100644 --- a/services/settings/cmd/settings/main.go +++ b/services/settings/cmd/settings/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/settings/pkg/command" "github.com/owncloud/ocis/v2/services/settings/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/sharing/cmd/sharing/main.go b/services/sharing/cmd/sharing/main.go index 54e0996e3fd..cb5b4e5cca5 100644 --- a/services/sharing/cmd/sharing/main.go +++ b/services/sharing/cmd/sharing/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/sharing/pkg/command" "github.com/owncloud/ocis/v2/services/sharing/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/sse/cmd/sse/main.go b/services/sse/cmd/sse/main.go index 8bd438f1148..9b31eea5282 100644 --- a/services/sse/cmd/sse/main.go +++ b/services/sse/cmd/sse/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/sse/pkg/command" "github.com/owncloud/ocis/v2/services/sse/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/storage-publiclink/cmd/storage-publiclink/main.go b/services/storage-publiclink/cmd/storage-publiclink/main.go index 6d2415a0070..e1637605c6c 100644 --- a/services/storage-publiclink/cmd/storage-publiclink/main.go +++ b/services/storage-publiclink/cmd/storage-publiclink/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/command" "github.com/owncloud/ocis/v2/services/storage-publiclink/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/storage-shares/cmd/storage-shares/main.go b/services/storage-shares/cmd/storage-shares/main.go index 8a8f9336beb..472cf04c8f0 100644 --- a/services/storage-shares/cmd/storage-shares/main.go +++ b/services/storage-shares/cmd/storage-shares/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/storage-shares/pkg/command" "github.com/owncloud/ocis/v2/services/storage-shares/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/storage-system/cmd/storage-system/main.go b/services/storage-system/cmd/storage-system/main.go index d9242ea0571..761e1ab2339 100644 --- a/services/storage-system/cmd/storage-system/main.go +++ b/services/storage-system/cmd/storage-system/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/storage-system/pkg/command" "github.com/owncloud/ocis/v2/services/storage-system/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/storage-users/cmd/storage-users/main.go b/services/storage-users/cmd/storage-users/main.go index c3c7bc7e3f0..142e5a44139 100644 --- a/services/storage-users/cmd/storage-users/main.go +++ b/services/storage-users/cmd/storage-users/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/storage-users/pkg/command" "github.com/owncloud/ocis/v2/services/storage-users/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/store/cmd/store/main.go b/services/store/cmd/store/main.go index ecf42e81938..3bbf8cff804 100644 --- a/services/store/cmd/store/main.go +++ b/services/store/cmd/store/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/store/pkg/command" "github.com/owncloud/ocis/v2/services/store/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/thumbnails/cmd/thumbnails/main.go b/services/thumbnails/cmd/thumbnails/main.go index f0a86f58bf2..9f3cce95662 100644 --- a/services/thumbnails/cmd/thumbnails/main.go +++ b/services/thumbnails/cmd/thumbnails/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/command" "github.com/owncloud/ocis/v2/services/thumbnails/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/userlog/cmd/userlog/main.go b/services/userlog/cmd/userlog/main.go index efdb7ae4b8d..2df9a2a98fe 100644 --- a/services/userlog/cmd/userlog/main.go +++ b/services/userlog/cmd/userlog/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/userlog/pkg/command" "github.com/owncloud/ocis/v2/services/userlog/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/users/cmd/user/main.go b/services/users/cmd/user/main.go index cae358d3c0b..6d692893242 100644 --- a/services/users/cmd/user/main.go +++ b/services/users/cmd/user/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/users/pkg/command" "github.com/owncloud/ocis/v2/services/users/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/web/cmd/web/main.go b/services/web/cmd/web/main.go index 9974c37fc9a..2ee45f9eebd 100644 --- a/services/web/cmd/web/main.go +++ b/services/web/cmd/web/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/web/pkg/command" "github.com/owncloud/ocis/v2/services/web/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/webdav/cmd/webdav/main.go b/services/webdav/cmd/webdav/main.go index 84449ec2e3e..08d0bdbbe4c 100644 --- a/services/webdav/cmd/webdav/main.go +++ b/services/webdav/cmd/webdav/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/webdav/pkg/command" "github.com/owncloud/ocis/v2/services/webdav/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } diff --git a/services/webfinger/cmd/webfinger/main.go b/services/webfinger/cmd/webfinger/main.go index f370d1c9e9e..b67f9ba63ec 100644 --- a/services/webfinger/cmd/webfinger/main.go +++ b/services/webfinger/cmd/webfinger/main.go @@ -1,14 +1,19 @@ package main import ( + "context" "os" + "os/signal" + "syscall" "github.com/owncloud/ocis/v2/services/webfinger/pkg/command" "github.com/owncloud/ocis/v2/services/webfinger/pkg/config/defaults" ) func main() { - if err := command.Execute(defaults.DefaultConfig()); err != nil { + cfg := defaults.DefaultConfig() + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + if err := command.Execute(cfg); err != nil { os.Exit(1) } } From 84f3670b953702f559abf8606cd7b931900a6a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:30:42 +0200 Subject: [PATCH 17/23] pass config context when running apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/antivirus/pkg/command/root.go | 2 +- services/app-provider/pkg/command/root.go | 2 +- services/app-registry/pkg/command/root.go | 2 +- services/audit/pkg/command/root.go | 2 +- services/auth-basic/pkg/command/root.go | 2 +- services/auth-bearer/pkg/command/root.go | 2 +- services/auth-machine/pkg/command/root.go | 2 +- services/auth-service/pkg/command/root.go | 2 +- services/clientlog/pkg/command/root.go | 2 +- services/eventhistory/pkg/command/root.go | 2 +- services/frontend/pkg/command/root.go | 2 +- services/graph/pkg/command/root.go | 2 +- services/groups/pkg/command/root.go | 2 +- services/idm/pkg/command/root.go | 2 +- services/idp/pkg/command/root.go | 2 +- services/invitations/pkg/command/root.go | 2 +- services/nats/pkg/command/root.go | 2 +- services/notifications/pkg/command/root.go | 2 +- services/ocdav/pkg/command/root.go | 2 +- services/ocm/pkg/command/root.go | 2 +- services/ocs/pkg/command/root.go | 2 +- services/policies/pkg/command/root.go | 2 +- services/postprocessing/pkg/command/root.go | 2 +- services/proxy/pkg/command/root.go | 2 +- services/search/pkg/command/root.go | 2 +- services/settings/pkg/command/root.go | 2 +- services/sharing/pkg/command/root.go | 2 +- services/sse/pkg/command/root.go | 2 +- services/storage-publiclink/pkg/command/root.go | 2 +- services/storage-shares/pkg/command/root.go | 2 +- services/storage-system/pkg/command/root.go | 2 +- services/storage-users/pkg/command/root.go | 2 +- services/store/pkg/command/root.go | 2 +- services/thumbnails/pkg/command/root.go | 2 +- services/userlog/pkg/command/root.go | 2 +- services/users/pkg/command/root.go | 2 +- services/web/pkg/command/root.go | 2 +- services/webdav/pkg/command/root.go | 2 +- services/webfinger/pkg/command/root.go | 2 +- 39 files changed, 39 insertions(+), 39 deletions(-) diff --git a/services/antivirus/pkg/command/root.go b/services/antivirus/pkg/command/root.go index 2884482748e..4683d3bc52c 100644 --- a/services/antivirus/pkg/command/root.go +++ b/services/antivirus/pkg/command/root.go @@ -25,5 +25,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/app-provider/pkg/command/root.go b/services/app-provider/pkg/command/root.go index d7bbe2bb4ff..42ac00c4940 100644 --- a/services/app-provider/pkg/command/root.go +++ b/services/app-provider/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/app-registry/pkg/command/root.go b/services/app-registry/pkg/command/root.go index 9f20d6051a3..41582af228e 100644 --- a/services/app-registry/pkg/command/root.go +++ b/services/app-registry/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/audit/pkg/command/root.go b/services/audit/pkg/command/root.go index abe6054a56a..c52fd880deb 100644 --- a/services/audit/pkg/command/root.go +++ b/services/audit/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/auth-basic/pkg/command/root.go b/services/auth-basic/pkg/command/root.go index cb53a0a6670..46823bc174a 100644 --- a/services/auth-basic/pkg/command/root.go +++ b/services/auth-basic/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/auth-bearer/pkg/command/root.go b/services/auth-bearer/pkg/command/root.go index c923e706fb2..c22b4f9ae3b 100644 --- a/services/auth-bearer/pkg/command/root.go +++ b/services/auth-bearer/pkg/command/root.go @@ -33,7 +33,7 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } // SutureService allows for the accounts command to be embedded and supervised by a suture supervisor tree. diff --git a/services/auth-machine/pkg/command/root.go b/services/auth-machine/pkg/command/root.go index fe153cd7847..733789b9796 100644 --- a/services/auth-machine/pkg/command/root.go +++ b/services/auth-machine/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/auth-service/pkg/command/root.go b/services/auth-service/pkg/command/root.go index 2fd57dd7adb..f37d4584c72 100644 --- a/services/auth-service/pkg/command/root.go +++ b/services/auth-service/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/clientlog/pkg/command/root.go b/services/clientlog/pkg/command/root.go index 389caf1bb21..ca9b26166be 100644 --- a/services/clientlog/pkg/command/root.go +++ b/services/clientlog/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/eventhistory/pkg/command/root.go b/services/eventhistory/pkg/command/root.go index 683c716a30b..a1d27a56363 100644 --- a/services/eventhistory/pkg/command/root.go +++ b/services/eventhistory/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/frontend/pkg/command/root.go b/services/frontend/pkg/command/root.go index ab4fd045238..0e906f15ea6 100644 --- a/services/frontend/pkg/command/root.go +++ b/services/frontend/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/graph/pkg/command/root.go b/services/graph/pkg/command/root.go index 5c9fae28940..dd967ffbedd 100644 --- a/services/graph/pkg/command/root.go +++ b/services/graph/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Usage: "Serve Graph API for oCIS", Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/groups/pkg/command/root.go b/services/groups/pkg/command/root.go index fdc14e68564..ba2a991b40b 100644 --- a/services/groups/pkg/command/root.go +++ b/services/groups/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/idm/pkg/command/root.go b/services/idm/pkg/command/root.go index 85134a4375d..6e6c9c4dc8f 100644 --- a/services/idm/pkg/command/root.go +++ b/services/idm/pkg/command/root.go @@ -31,5 +31,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/idp/pkg/command/root.go b/services/idp/pkg/command/root.go index 724620d7da3..b6707989cde 100644 --- a/services/idp/pkg/command/root.go +++ b/services/idp/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/invitations/pkg/command/root.go b/services/invitations/pkg/command/root.go index aa8c993ab37..7425baf0d39 100644 --- a/services/invitations/pkg/command/root.go +++ b/services/invitations/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/nats/pkg/command/root.go b/services/nats/pkg/command/root.go index 067bd39cd57..483d91b63c0 100644 --- a/services/nats/pkg/command/root.go +++ b/services/nats/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/notifications/pkg/command/root.go b/services/notifications/pkg/command/root.go index aa048245a01..2833e622edb 100644 --- a/services/notifications/pkg/command/root.go +++ b/services/notifications/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/ocdav/pkg/command/root.go b/services/ocdav/pkg/command/root.go index 5b1afc5b301..6dd8518683d 100644 --- a/services/ocdav/pkg/command/root.go +++ b/services/ocdav/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/ocm/pkg/command/root.go b/services/ocm/pkg/command/root.go index 7187fe52735..e524c73bd33 100644 --- a/services/ocm/pkg/command/root.go +++ b/services/ocm/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/ocs/pkg/command/root.go b/services/ocs/pkg/command/root.go index 569ff06ab40..1d2d38d8818 100644 --- a/services/ocs/pkg/command/root.go +++ b/services/ocs/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/policies/pkg/command/root.go b/services/policies/pkg/command/root.go index 368ca7657c8..5926061c539 100644 --- a/services/policies/pkg/command/root.go +++ b/services/policies/pkg/command/root.go @@ -25,5 +25,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/postprocessing/pkg/command/root.go b/services/postprocessing/pkg/command/root.go index f4a20863206..1e9796445fb 100644 --- a/services/postprocessing/pkg/command/root.go +++ b/services/postprocessing/pkg/command/root.go @@ -31,5 +31,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/proxy/pkg/command/root.go b/services/proxy/pkg/command/root.go index 65d32b57535..b918424d6d8 100644 --- a/services/proxy/pkg/command/root.go +++ b/services/proxy/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/search/pkg/command/root.go b/services/search/pkg/command/root.go index e850b3612fa..f0f9d05b713 100644 --- a/services/search/pkg/command/root.go +++ b/services/search/pkg/command/root.go @@ -31,5 +31,5 @@ func Execute(cfg *config.Config) error { Usage: "Serve search API for oCIS", Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/settings/pkg/command/root.go b/services/settings/pkg/command/root.go index 641cf491c6e..d9679de4107 100644 --- a/services/settings/pkg/command/root.go +++ b/services/settings/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/sharing/pkg/command/root.go b/services/sharing/pkg/command/root.go index fba13bf9050..4330a939b40 100644 --- a/services/sharing/pkg/command/root.go +++ b/services/sharing/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/sse/pkg/command/root.go b/services/sse/pkg/command/root.go index f3a6e4b2769..290cc700112 100644 --- a/services/sse/pkg/command/root.go +++ b/services/sse/pkg/command/root.go @@ -26,5 +26,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/storage-publiclink/pkg/command/root.go b/services/storage-publiclink/pkg/command/root.go index 9ca05cc710e..a3822e8b0e1 100644 --- a/services/storage-publiclink/pkg/command/root.go +++ b/services/storage-publiclink/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/storage-shares/pkg/command/root.go b/services/storage-shares/pkg/command/root.go index fd36affa1ef..2295b539da3 100644 --- a/services/storage-shares/pkg/command/root.go +++ b/services/storage-shares/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/storage-system/pkg/command/root.go b/services/storage-system/pkg/command/root.go index 92b6e757af6..a9786726f17 100644 --- a/services/storage-system/pkg/command/root.go +++ b/services/storage-system/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/storage-users/pkg/command/root.go b/services/storage-users/pkg/command/root.go index 777ec6f2f67..d24d37a6c1c 100644 --- a/services/storage-users/pkg/command/root.go +++ b/services/storage-users/pkg/command/root.go @@ -32,5 +32,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/store/pkg/command/root.go b/services/store/pkg/command/root.go index 8e208dba5b2..d105b28f9f8 100644 --- a/services/store/pkg/command/root.go +++ b/services/store/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/thumbnails/pkg/command/root.go b/services/thumbnails/pkg/command/root.go index 8ddf1c23d67..2e12c42c3bc 100644 --- a/services/thumbnails/pkg/command/root.go +++ b/services/thumbnails/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/userlog/pkg/command/root.go b/services/userlog/pkg/command/root.go index dd80e5acb61..8b8d1b1a5c7 100644 --- a/services/userlog/pkg/command/root.go +++ b/services/userlog/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/users/pkg/command/root.go b/services/users/pkg/command/root.go index e0039b1c390..8952e628aac 100644 --- a/services/users/pkg/command/root.go +++ b/services/users/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/web/pkg/command/root.go b/services/web/pkg/command/root.go index 91a648c1a2d..6f91fb895f2 100644 --- a/services/web/pkg/command/root.go +++ b/services/web/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/webdav/pkg/command/root.go b/services/webdav/pkg/command/root.go index 8a1d46b23ac..e2d6cf9f7fc 100644 --- a/services/webdav/pkg/command/root.go +++ b/services/webdav/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } diff --git a/services/webfinger/pkg/command/root.go b/services/webfinger/pkg/command/root.go index 4d553a26559..a6d30c53cfa 100644 --- a/services/webfinger/pkg/command/root.go +++ b/services/webfinger/pkg/command/root.go @@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error { Commands: GetCommands(cfg), }) - return app.Run(os.Args) + return app.RunContext(cfg.Context, os.Args) } From c40ff483a780ad260fb435e0aa0f4da67c96b947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:33:57 +0200 Subject: [PATCH 18/23] replace defineContext with context from app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/app-provider/pkg/command/server.go | 13 +------------ services/app-registry/pkg/command/server.go | 13 +------------ services/auth-basic/pkg/command/server.go | 13 +------------ services/auth-bearer/pkg/command/server.go | 13 +------------ services/auth-machine/pkg/command/server.go | 13 +------------ services/auth-service/pkg/command/server.go | 13 +------------ services/frontend/pkg/command/server.go | 13 +------------ services/groups/pkg/command/server.go | 13 +------------ services/ocdav/pkg/command/server.go | 13 +------------ services/ocm/pkg/command/server.go | 13 +------------ services/sharing/pkg/command/server.go | 13 +------------ services/storage-publiclink/pkg/command/server.go | 13 +------------ services/storage-shares/pkg/command/server.go | 13 +------------ services/storage-system/pkg/command/server.go | 13 +------------ services/storage-users/pkg/command/server.go | 13 +------------ services/users/pkg/command/server.go | 13 +------------ 16 files changed, 16 insertions(+), 192 deletions(-) diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 35ec85888a7..ff001ad9ad8 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index d540c4a5be7..61a27a3c0b9 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -37,7 +37,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -86,14 +86,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index e39e493f1c2..6146e1049a2 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -39,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -104,14 +104,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 0fa78ee0db3..d2e8863486a 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 2e27fceb425..070b00a6df4 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index ad28f3c79dc..05e0ca124d7 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -92,14 +92,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index f7e6f9d7bd2..83c011be6d0 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -102,14 +102,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 69b7215d0f1..3bdf0227045 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -39,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -104,14 +104,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 447e72d8c78..09dc1368555 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -35,7 +35,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -124,14 +124,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 43a2b7cdecb..6dd6f8f2fc9 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -97,14 +97,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 108c8510a70..aa22d938620 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -39,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -108,14 +108,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 67664bcc3d5..b6eade925d2 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index e615fc2818a..8cb03f746ad 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -91,14 +91,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 0064135ae88..8dd29f49e02 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -38,7 +38,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -96,14 +96,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index da5feee7065..a84512e126c 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -40,7 +40,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -128,14 +128,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 823f60812b4..6095e2ca2ba 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -39,7 +39,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := defineContext(cfg) + ctx, cancel := context.WithCancel(c.Context) defer cancel() @@ -104,14 +104,3 @@ func Server(cfg *config.Config) *cli.Command { }, } } - -// defineContext sets the context for the service. If there is a context configured it will create a new child from it, -// if not, it will create a root context that can be cancelled. -func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { - return func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() -} From 6ed9ef3b5cbbd9e69e04481c234e8d7579f35cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 13:37:39 +0200 Subject: [PATCH 19/23] rely on context from app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/antivirus/pkg/command/server.go | 9 ++------- services/audit/pkg/command/server.go | 7 +------ services/clientlog/pkg/command/server.go | 7 +------ services/eventhistory/pkg/command/server.go | 9 ++------- services/graph/pkg/command/server.go | 7 +------ services/idm/pkg/command/resetpw.go | 7 +------ services/idm/pkg/command/server.go | 7 +------ services/idp/pkg/command/server.go | 9 ++------- services/invitations/pkg/command/server.go | 9 ++------- services/nats/pkg/command/server.go | 7 +------ services/notifications/pkg/command/server.go | 8 +------- services/ocs/pkg/command/server.go | 9 ++------- services/policies/pkg/command/server.go | 9 ++------- services/postprocessing/pkg/command/server.go | 12 +++--------- services/proxy/pkg/command/server.go | 7 +------ services/search/pkg/command/server.go | 7 +------ services/settings/pkg/command/server.go | 7 +------ services/sse/pkg/command/server.go | 9 ++------- services/store/pkg/command/server.go | 12 ++---------- services/thumbnails/pkg/command/server.go | 9 ++------- services/userlog/pkg/command/server.go | 7 +------ services/web/pkg/command/server.go | 9 ++------- services/webdav/pkg/command/server.go | 9 ++------- services/webfinger/pkg/command/server.go | 9 ++------- 24 files changed, 38 insertions(+), 163 deletions(-) diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 32e2fd8b44f..0acbd873212 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -29,13 +29,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 6c55e638c1f..aeaf01128fe 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -34,12 +34,7 @@ func Server(cfg *config.Config) *cli.Command { gr = run.Group{} logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 4dcc14da711..3302e480974 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -45,12 +45,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 3a942b177f7..14fba7eddd0 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -47,13 +47,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 2c547aefeb7..0cde2d4db4e 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -35,12 +35,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() defer cancel() diff --git a/services/idm/pkg/command/resetpw.go b/services/idm/pkg/command/resetpw.go index 415b0479220..7ab08b9bc4c 100644 --- a/services/idm/pkg/command/resetpw.go +++ b/services/idm/pkg/command/resetpw.go @@ -32,12 +32,7 @@ func ResetPassword(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() return resetPassword(ctx, logger, cfg) diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 048ef8d3b68..16e8a081feb 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -40,12 +40,7 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 48f431f5921..78f658f1469 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -56,13 +56,8 @@ func Server(cfg *config.Config) *cli.Command { } var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 01000c7d727..183627c2d2f 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -37,13 +37,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New(metrics.Logger(logger)) + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New(metrics.Logger(logger)) ) defer cancel() diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index e118d43312b..f7b00f2934b 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -33,12 +33,7 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 55b3c7ad3c4..0b635a2a2a0 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -53,13 +53,7 @@ func Server(cfg *config.Config) *cli.Command { gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - + ctx, cancel := context.WithCancel(c.Context) defer cancel() { diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index c252872eca3..44ffb164daa 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -43,13 +43,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 3af423b02d1..61fa78f6ad4 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -35,13 +35,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index f8b9095cd91..6264b1bfb2b 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -36,15 +36,9 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var ( - gr = run.Group{} - logger = logging.Configure(cfg.Service.Name, cfg.Log) - - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + gr = run.Group{} + logger = logging.Configure(cfg.Service.Name, cfg.Log) + ctx, cancel = context.WithCancel(c.Context) ) defer cancel() diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 2ce79a0a52a..996c0c80f1b 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -120,12 +120,7 @@ func Server(cfg *config.Config) *cli.Command { m := metrics.New() gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index 4983ab9a83b..1e823e42e4e 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -41,12 +41,7 @@ func Server(cfg *config.Config) *cli.Command { return err } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() mtrcs := metrics.New() diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index b06302188d4..56dad239516 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -44,12 +44,7 @@ func Server(cfg *config.Config) *cli.Command { } servers := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) defer cancel() mtrcs := metrics.New() diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index ac027d606d2..06491d29062 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -37,13 +37,8 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - logger = log.NewLogger( + ctx, cancel = context.WithCancel(c.Context) + logger = log.NewLogger( log.Name(cfg.Service.Name), log.Level(cfg.Log.Level), log.Pretty(cfg.Log.Pretty), diff --git a/services/store/pkg/command/server.go b/services/store/pkg/command/server.go index 854bf0e7bb2..9d32b3194cf 100644 --- a/services/store/pkg/command/server.go +++ b/services/store/pkg/command/server.go @@ -35,9 +35,6 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - if err != nil { - return err - } cfg.GrpcClient, err = ogrpc.NewClient( append(ogrpc.GetClientOptions(cfg.GRPCClientTLS), ogrpc.WithTraceProvider(traceProvider))..., ) @@ -47,13 +44,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index 1e453610bd5..1e8562c7afc 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -43,13 +43,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index 00637c85db8..ddded1b441d 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -70,12 +70,7 @@ func Server(cfg *config.Config) *cli.Command { } gr := run.Group{} - ctx, cancel := func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() + ctx, cancel := context.WithCancel(c.Context) mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index c967ece8476..7fe895f2923 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -49,13 +49,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index a189dd36e75..4c43f00dcc0 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -44,13 +44,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New() + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New() ) defer cancel() diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index cfba7bf6834..f81071d4572 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -38,13 +38,8 @@ func Server(cfg *config.Config) *cli.Command { var ( gr = run.Group{} - ctx, cancel = func() (context.Context, context.CancelFunc) { - if cfg.Context == nil { - return context.WithCancel(context.Background()) - } - return context.WithCancel(cfg.Context) - }() - metrics = metrics.New(metrics.Logger(logger)) + ctx, cancel = context.WithCancel(c.Context) + metrics = metrics.New(metrics.Logger(logger)) ) defer cancel() From e120da451f5bd92be475d248a4fcc3a4a247ae85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 24 Jul 2024 14:02:52 +0200 Subject: [PATCH 20/23] do not force exit to let all services shutdown gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/app-provider/pkg/command/server.go | 1 - services/app-registry/pkg/command/server.go | 1 - services/audit/pkg/command/server.go | 2 -- services/auth-basic/pkg/command/server.go | 1 - services/auth-bearer/pkg/command/server.go | 1 - services/auth-machine/pkg/command/server.go | 1 - services/auth-service/pkg/command/server.go | 1 - services/clientlog/pkg/command/server.go | 2 -- services/frontend/pkg/command/server.go | 1 - services/graph/pkg/command/server.go | 2 -- services/groups/pkg/command/server.go | 1 - services/idm/pkg/command/server.go | 1 - services/idp/pkg/command/server.go | 1 - services/invitations/pkg/command/server.go | 2 -- services/nats/pkg/command/server.go | 2 -- services/ocdav/pkg/command/server.go | 2 -- services/ocm/pkg/command/server.go | 1 - services/ocs/pkg/command/server.go | 2 -- services/postprocessing/pkg/command/server.go | 1 - services/proxy/pkg/command/server.go | 2 -- services/settings/pkg/command/server.go | 3 --- services/sharing/pkg/command/server.go | 1 - services/storage-publiclink/pkg/command/server.go | 1 - services/storage-shares/pkg/command/server.go | 1 - services/storage-system/pkg/command/server.go | 1 - services/storage-users/pkg/command/server.go | 1 - services/store/pkg/command/server.go | 2 -- services/thumbnails/pkg/command/server.go | 2 -- services/userlog/pkg/command/server.go | 2 -- services/users/pkg/command/server.go | 1 - services/web/pkg/command/server.go | 1 - services/webdav/pkg/command/server.go | 2 -- services/webfinger/pkg/command/server.go | 2 -- 33 files changed, 48 deletions(-) diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index ff001ad9ad8..450bb2d7abb 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 61a27a3c0b9..b8d1a790bfb 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -60,7 +60,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index aeaf01128fe..93f945e4976 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/stream" @@ -55,7 +54,6 @@ func Server(cfg *config.Config) *cli.Command { Err(err). Msg("Shutting down server") cancel() - os.Exit(1) }) { diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index 6146e1049a2..f5e0990e9bc 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -74,7 +74,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index d2e8863486a..1c8e239b3ae 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 070b00a6df4..0a4dcbb59b0 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 05e0ca124d7..58ab0dde1d8 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 3302e480974..a0f975403a5 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/stream" @@ -96,7 +95,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index 83c011be6d0..cd22a4be7f1 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -65,7 +65,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 0cde2d4db4e..7c10c330ba1 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -64,7 +63,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 3bdf0227045..cd6dffcb6d3 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -74,7 +74,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 16e8a081feb..3ec90806ac6 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -90,7 +90,6 @@ func Server(cfg *config.Config) *cli.Command { Err(err). Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 78f658f1469..02bf30eaa0f 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -90,7 +90,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 183627c2d2f..0b2b358cda6 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -84,7 +83,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index f7b00f2934b..983909d8c67 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "fmt" - "os" "github.com/oklog/run" @@ -109,7 +108,6 @@ func Server(cfg *config.Config) *cli.Command { natsServer.Shutdown() cancel() - os.Exit(1) }) return gr.Run() diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 09dc1368555..099189968cb 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/cs3org/reva/v2/pkg/micro/ocdav" "github.com/cs3org/reva/v2/pkg/sharedconf" @@ -101,7 +100,6 @@ func Server(cfg *config.Config) *cli.Command { Str("server", c.Command.Name). Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 6dd6f8f2fc9..6dc234fda9a 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -62,7 +62,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index 44ffb164daa..92bedd6c883 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" "github.com/owncloud/ocis/v2/ocis-pkg/version" @@ -77,7 +76,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index 6264b1bfb2b..69873db3197 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -81,7 +81,6 @@ func Server(cfg *config.Config) *cli.Command { Err(err). Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 996c0c80f1b..d00b3af6d4c 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "net/http" - "os" "time" "github.com/go-chi/chi/v5" @@ -172,7 +171,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 56dad239516..3b80b64e425 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -71,7 +70,6 @@ func Server(cfg *config.Config) *cli.Command { servers.Add(httpServer.Run, func(_ error) { logger.Info().Str("server", "http").Msg("Shutting down server") cancel() - os.Exit(1) }) // prepare a gRPC server and add it to the group run. @@ -87,7 +85,6 @@ func Server(cfg *config.Config) *cli.Command { servers.Add(grpcServer.Run, func(_ error) { logger.Info().Str("server", "grpc").Msg("Shutting down server") cancel() - os.Exit(1) }) // prepare a debug server and add it to the group run. diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index aa22d938620..d8f0a069fdc 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -77,7 +77,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index b6eade925d2..0002e37a875 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index 8cb03f746ad..152756c9a92 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 8dd29f49e02..a4664fcc1e3 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -61,7 +61,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index a84512e126c..6d851b80714 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -63,7 +63,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/store/pkg/command/server.go b/services/store/pkg/command/server.go index 9d32b3194cf..8971d75517d 100644 --- a/services/store/pkg/command/server.go +++ b/services/store/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" @@ -68,7 +67,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index 1e8562c7afc..b66924b2504 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -69,7 +68,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) server, err := debug.Server( diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index ddded1b441d..8e43ddfda69 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/cs3org/reva/v2/pkg/events" "github.com/cs3org/reva/v2/pkg/events/stream" @@ -141,7 +140,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 6095e2ca2ba..f70a79fefe4 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -74,7 +74,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) debugServer, err := debug.Server( diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index 7fe895f2923..693eaa040d4 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -88,7 +88,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index 4c43f00dcc0..6e3656d2876 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -79,7 +78,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index f81071d4572..8530de55d7f 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -3,7 +3,6 @@ package command import ( "context" "fmt" - "os" "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" @@ -92,7 +91,6 @@ func Server(cfg *config.Config) *cli.Command { Msg("Shutting down server") cancel() - os.Exit(1) }) } From 1200a2f44269c53eb3e8b5514f4c465eb1284694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 29 Jul 2024 16:28:13 +0200 Subject: [PATCH 21/23] only register signal handling once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- ocis/pkg/command/root.go | 2 +- ocis/pkg/runtime/service/service.go | 18 +++++++----------- services/antivirus/cmd/antivirus/main.go | 2 +- services/app-provider/cmd/app-provider/main.go | 2 +- services/app-registry/cmd/app-registry/main.go | 2 +- services/audit/cmd/audit/main.go | 2 +- services/auth-basic/cmd/auth-basic/main.go | 2 +- services/auth-bearer/cmd/auth-bearer/main.go | 2 +- services/auth-machine/cmd/auth-machine/main.go | 2 +- services/auth-service/cmd/auth-service/main.go | 2 +- services/clientlog/cmd/clientlog/main.go | 2 +- services/eventhistory/cmd/eventhistory/main.go | 2 +- services/frontend/cmd/frontend/main.go | 2 +- services/gateway/cmd/gateway/main.go | 2 +- services/graph/cmd/graph/main.go | 2 +- services/groups/cmd/groups/main.go | 2 +- services/idm/cmd/idm/main.go | 2 +- services/idp/cmd/idp/main.go | 2 +- services/invitations/cmd/invitations/main.go | 2 +- services/nats/cmd/nats/main.go | 2 +- .../notifications/cmd/notifications/main.go | 2 +- services/ocdav/cmd/ocdav/main.go | 2 +- services/ocm/cmd/ocm/main.go | 2 +- services/ocs/cmd/ocs/main.go | 2 +- services/policies/cmd/policies/main.go | 2 +- .../postprocessing/cmd/postprocessing/main.go | 2 +- services/proxy/cmd/proxy/main.go | 2 +- services/search/cmd/search/main.go | 2 +- services/settings/cmd/settings/main.go | 2 +- services/sharing/cmd/sharing/main.go | 2 +- services/sse/cmd/sse/main.go | 2 +- .../cmd/storage-publiclink/main.go | 2 +- .../storage-shares/cmd/storage-shares/main.go | 2 +- .../storage-system/cmd/storage-system/main.go | 2 +- .../storage-users/cmd/storage-users/main.go | 2 +- services/store/cmd/store/main.go | 2 +- services/thumbnails/cmd/thumbnails/main.go | 2 +- services/userlog/cmd/userlog/main.go | 2 +- services/users/cmd/user/main.go | 2 +- services/web/cmd/web/main.go | 2 +- services/webdav/cmd/webdav/main.go | 2 +- services/webfinger/cmd/webfinger/main.go | 2 +- 42 files changed, 48 insertions(+), 52 deletions(-) diff --git a/ocis/pkg/command/root.go b/ocis/pkg/command/root.go index 666ee0544f0..6dd7136e41e 100644 --- a/ocis/pkg/command/root.go +++ b/ocis/pkg/command/root.go @@ -28,6 +28,6 @@ func Execute() error { ) } - ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) return app.RunContext(ctx, os.Args) } diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index ce00289ce75..3536cfa0455 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -7,10 +7,8 @@ import ( "net/http" "net/rpc" "os" - "os/signal" "sort" "strings" - "syscall" "time" "github.com/cenkalti/backoff" @@ -349,9 +347,8 @@ func Start(ctx context.Context, o ...Option) error { return err } - // halt listens for interrupt signals and blocks. - halt := make(chan os.Signal, 1) - signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) + // get a cancel function to stop the service + ctx, cancel := context.WithCancel(ctx) // tolerance controls backoff cycles from the supervisor. tolerance := 5 @@ -363,7 +360,7 @@ func Start(ctx context.Context, o ...Option) error { if e.Type() == suture.EventTypeBackoff { totalBackoff++ if totalBackoff == tolerance { - halt <- os.Interrupt + cancel() } } s.Log.Info().Str("event", e.String()).Msg(fmt.Sprintf("supervisor: %v", e.Map()["supervisor_name"])) @@ -411,8 +408,8 @@ func Start(ctx context.Context, o ...Option) error { // https://pkg.go.dev/github.com/thejerf/suture/v4@v4.0.0#Supervisor go s.Supervisor.ServeBackground(s.context) - // trap will block on halt channel for interruptions. - go trap(s, halt) + // trap will block on context done channel for interruptions. + go trap(s, ctx) for i, service := range s.Services { scheduleServiceTokens(s, service) @@ -495,9 +492,8 @@ func (s *Service) List(_ struct{}, reply *string) error { // trap blocks on halt channel. When the runtime is interrupted it // signals the controller to stop any supervised process. -func trap(s *Service, halt chan os.Signal) { - <-halt - s.cancel() +func trap(s *Service, ctx context.Context) { + <-ctx.Done() for sName := range s.serviceToken { for i := range s.serviceToken[sName] { if err := s.Supervisor.Remove(s.serviceToken[sName][i]); err != nil { diff --git a/services/antivirus/cmd/antivirus/main.go b/services/antivirus/cmd/antivirus/main.go index 174e6fe3fbc..8f0332ad1db 100644 --- a/services/antivirus/cmd/antivirus/main.go +++ b/services/antivirus/cmd/antivirus/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/app-provider/cmd/app-provider/main.go b/services/app-provider/cmd/app-provider/main.go index 42b66fd9c07..1d7474d45b2 100644 --- a/services/app-provider/cmd/app-provider/main.go +++ b/services/app-provider/cmd/app-provider/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/app-registry/cmd/app-registry/main.go b/services/app-registry/cmd/app-registry/main.go index e00af3f2abc..ddb4faa2952 100644 --- a/services/app-registry/cmd/app-registry/main.go +++ b/services/app-registry/cmd/app-registry/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/audit/cmd/audit/main.go b/services/audit/cmd/audit/main.go index 8b33880d6c8..56413c60b55 100644 --- a/services/audit/cmd/audit/main.go +++ b/services/audit/cmd/audit/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/auth-basic/cmd/auth-basic/main.go b/services/auth-basic/cmd/auth-basic/main.go index 784d715be54..6235d5da74a 100644 --- a/services/auth-basic/cmd/auth-basic/main.go +++ b/services/auth-basic/cmd/auth-basic/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/auth-bearer/cmd/auth-bearer/main.go b/services/auth-bearer/cmd/auth-bearer/main.go index 4bc12ab09c4..8cab6c04a11 100644 --- a/services/auth-bearer/cmd/auth-bearer/main.go +++ b/services/auth-bearer/cmd/auth-bearer/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/auth-machine/cmd/auth-machine/main.go b/services/auth-machine/cmd/auth-machine/main.go index aeb79d5ccf0..f2b0bdc360d 100644 --- a/services/auth-machine/cmd/auth-machine/main.go +++ b/services/auth-machine/cmd/auth-machine/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/auth-service/cmd/auth-service/main.go b/services/auth-service/cmd/auth-service/main.go index 81ce1579e95..70b2c3d7f91 100644 --- a/services/auth-service/cmd/auth-service/main.go +++ b/services/auth-service/cmd/auth-service/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/clientlog/cmd/clientlog/main.go b/services/clientlog/cmd/clientlog/main.go index cdd91f273a3..9c6595c600c 100644 --- a/services/clientlog/cmd/clientlog/main.go +++ b/services/clientlog/cmd/clientlog/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/eventhistory/cmd/eventhistory/main.go b/services/eventhistory/cmd/eventhistory/main.go index 4a1d3f87016..47eb6483c10 100644 --- a/services/eventhistory/cmd/eventhistory/main.go +++ b/services/eventhistory/cmd/eventhistory/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/frontend/cmd/frontend/main.go b/services/frontend/cmd/frontend/main.go index 8e12e7761aa..a3e887680f5 100644 --- a/services/frontend/cmd/frontend/main.go +++ b/services/frontend/cmd/frontend/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/gateway/cmd/gateway/main.go b/services/gateway/cmd/gateway/main.go index 503e12de1c1..766b15bcf99 100644 --- a/services/gateway/cmd/gateway/main.go +++ b/services/gateway/cmd/gateway/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/graph/cmd/graph/main.go b/services/graph/cmd/graph/main.go index 0775fcb4874..b0d9189e0a0 100644 --- a/services/graph/cmd/graph/main.go +++ b/services/graph/cmd/graph/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/groups/cmd/groups/main.go b/services/groups/cmd/groups/main.go index d13447d4964..c1d4afadbef 100644 --- a/services/groups/cmd/groups/main.go +++ b/services/groups/cmd/groups/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/idm/cmd/idm/main.go b/services/idm/cmd/idm/main.go index ab6af89f2bd..e61c15349d0 100644 --- a/services/idm/cmd/idm/main.go +++ b/services/idm/cmd/idm/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/idp/cmd/idp/main.go b/services/idp/cmd/idp/main.go index d3def5ab1c5..de20d3a5b3c 100644 --- a/services/idp/cmd/idp/main.go +++ b/services/idp/cmd/idp/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/invitations/cmd/invitations/main.go b/services/invitations/cmd/invitations/main.go index 86da31fcb1c..8c9a45aeabc 100644 --- a/services/invitations/cmd/invitations/main.go +++ b/services/invitations/cmd/invitations/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/nats/cmd/nats/main.go b/services/nats/cmd/nats/main.go index 2e75edad3d2..347a2cc3e9e 100644 --- a/services/nats/cmd/nats/main.go +++ b/services/nats/cmd/nats/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/notifications/cmd/notifications/main.go b/services/notifications/cmd/notifications/main.go index 1836a24f857..73f31b88fc6 100644 --- a/services/notifications/cmd/notifications/main.go +++ b/services/notifications/cmd/notifications/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/ocdav/cmd/ocdav/main.go b/services/ocdav/cmd/ocdav/main.go index 964af1667ca..5a6d24390f0 100644 --- a/services/ocdav/cmd/ocdav/main.go +++ b/services/ocdav/cmd/ocdav/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/ocm/cmd/ocm/main.go b/services/ocm/cmd/ocm/main.go index 6a4b7926d8b..77a2913ba61 100644 --- a/services/ocm/cmd/ocm/main.go +++ b/services/ocm/cmd/ocm/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/ocs/cmd/ocs/main.go b/services/ocs/cmd/ocs/main.go index 8ae7d026221..96de1a08e17 100644 --- a/services/ocs/cmd/ocs/main.go +++ b/services/ocs/cmd/ocs/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/policies/cmd/policies/main.go b/services/policies/cmd/policies/main.go index 09abb5e85ed..e774e8c4a64 100644 --- a/services/policies/cmd/policies/main.go +++ b/services/policies/cmd/policies/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/postprocessing/cmd/postprocessing/main.go b/services/postprocessing/cmd/postprocessing/main.go index e42d50ccdfe..869d23db024 100644 --- a/services/postprocessing/cmd/postprocessing/main.go +++ b/services/postprocessing/cmd/postprocessing/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/proxy/cmd/proxy/main.go b/services/proxy/cmd/proxy/main.go index 9c51a443e45..889bc6772ee 100644 --- a/services/proxy/cmd/proxy/main.go +++ b/services/proxy/cmd/proxy/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/search/cmd/search/main.go b/services/search/cmd/search/main.go index 807b6642733..1426e298d38 100644 --- a/services/search/cmd/search/main.go +++ b/services/search/cmd/search/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/settings/cmd/settings/main.go b/services/settings/cmd/settings/main.go index 8833af4bbeb..965c6385401 100644 --- a/services/settings/cmd/settings/main.go +++ b/services/settings/cmd/settings/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/sharing/cmd/sharing/main.go b/services/sharing/cmd/sharing/main.go index cb5b4e5cca5..c059753eb0b 100644 --- a/services/sharing/cmd/sharing/main.go +++ b/services/sharing/cmd/sharing/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/sse/cmd/sse/main.go b/services/sse/cmd/sse/main.go index 9b31eea5282..4e951b92514 100644 --- a/services/sse/cmd/sse/main.go +++ b/services/sse/cmd/sse/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/storage-publiclink/cmd/storage-publiclink/main.go b/services/storage-publiclink/cmd/storage-publiclink/main.go index e1637605c6c..2207a7829eb 100644 --- a/services/storage-publiclink/cmd/storage-publiclink/main.go +++ b/services/storage-publiclink/cmd/storage-publiclink/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/storage-shares/cmd/storage-shares/main.go b/services/storage-shares/cmd/storage-shares/main.go index 472cf04c8f0..5a292e0ec2f 100644 --- a/services/storage-shares/cmd/storage-shares/main.go +++ b/services/storage-shares/cmd/storage-shares/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/storage-system/cmd/storage-system/main.go b/services/storage-system/cmd/storage-system/main.go index 761e1ab2339..9f2bdaa45e7 100644 --- a/services/storage-system/cmd/storage-system/main.go +++ b/services/storage-system/cmd/storage-system/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/storage-users/cmd/storage-users/main.go b/services/storage-users/cmd/storage-users/main.go index 142e5a44139..62bf86fd007 100644 --- a/services/storage-users/cmd/storage-users/main.go +++ b/services/storage-users/cmd/storage-users/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/store/cmd/store/main.go b/services/store/cmd/store/main.go index 3bbf8cff804..4384dfab8c8 100644 --- a/services/store/cmd/store/main.go +++ b/services/store/cmd/store/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/thumbnails/cmd/thumbnails/main.go b/services/thumbnails/cmd/thumbnails/main.go index 9f3cce95662..f2e8ce62676 100644 --- a/services/thumbnails/cmd/thumbnails/main.go +++ b/services/thumbnails/cmd/thumbnails/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/userlog/cmd/userlog/main.go b/services/userlog/cmd/userlog/main.go index 2df9a2a98fe..58d53b06360 100644 --- a/services/userlog/cmd/userlog/main.go +++ b/services/userlog/cmd/userlog/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/users/cmd/user/main.go b/services/users/cmd/user/main.go index 6d692893242..35d221577cc 100644 --- a/services/users/cmd/user/main.go +++ b/services/users/cmd/user/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/web/cmd/web/main.go b/services/web/cmd/web/main.go index 2ee45f9eebd..2331767f35b 100644 --- a/services/web/cmd/web/main.go +++ b/services/web/cmd/web/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/webdav/cmd/webdav/main.go b/services/webdav/cmd/webdav/main.go index 08d0bdbbe4c..444ea77ff83 100644 --- a/services/webdav/cmd/webdav/main.go +++ b/services/webdav/cmd/webdav/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } diff --git a/services/webfinger/cmd/webfinger/main.go b/services/webfinger/cmd/webfinger/main.go index b67f9ba63ec..112094e8a4d 100644 --- a/services/webfinger/cmd/webfinger/main.go +++ b/services/webfinger/cmd/webfinger/main.go @@ -12,7 +12,7 @@ import ( func main() { cfg := defaults.DefaultConfig() - cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + cfg.Context, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP) if err := command.Execute(cfg); err != nil { os.Exit(1) } From 7e5978c0b9f3d54110c39b816c3123cd31482f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 22 Jul 2024 11:11:45 +0200 Subject: [PATCH 22/23] pass registration cfg to micro ocdav MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/ocdav/pkg/command/server.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 099189968cb..4272419e84d 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -9,6 +9,7 @@ import ( "github.com/oklog/run" "github.com/owncloud/ocis/v2/ocis-pkg/broker" "github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" + "github.com/owncloud/ocis/v2/ocis-pkg/registry" "github.com/owncloud/ocis/v2/ocis-pkg/tracing" "github.com/owncloud/ocis/v2/ocis-pkg/version" "github.com/owncloud/ocis/v2/services/ocdav/pkg/config" @@ -86,6 +87,8 @@ func Server(cfg *config.Config) *cli.Command { ocdav.MetricsNamespace("ocis"), ocdav.Tracing("Adding these strings is a workaround for ->", "https://github.com/cs3org/reva/issues/4131"), ocdav.WithTraceProvider(traceProvider), + ocdav.RegisterTTL(registry.GetRegisterTTL()), + ocdav.RegisterInterval(registry.GetRegisterInterval()), } s, err := ocdav.Service(opts...) From ecc3e299532b879e6977d6d2b344b472716dbbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 4 Oct 2024 09:51:44 +0200 Subject: [PATCH 23/23] fix changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-natsjskv-registry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/unreleased/fix-natsjskv-registry.md b/changelog/unreleased/fix-natsjskv-registry.md index 86dd84e15d0..87f1f29de72 100644 --- a/changelog/unreleased/fix-natsjskv-registry.md +++ b/changelog/unreleased/fix-natsjskv-registry.md @@ -1,4 +1,4 @@ -Fix: Repair nats-js-kv registry +Bugfix: Repair nats-js-kv registry The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it.