From 6e4de0abd3c74ec67925aac7cbed3a378d32593b Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 19 Apr 2021 13:32:38 +0200 Subject: [PATCH 1/3] config parsing on run command --- ocis/pkg/runtime/service/service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index d8a80dcc3cc..b0a5f1fabfb 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -194,6 +194,7 @@ func Start(o ...Option) error { // Start indicates the Service Controller to start a new supervised service as an OS thread. func (s *Service) Start(name string, reply *int) error { swap := deepcopy.Copy(s.cfg) + swap.(*ociscfg.Config).Mode = ociscfg.UNSUPERVISED if _, ok := s.ServicesRegistry[name]; ok { *reply = 0 s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config)))) From 610c6fcbec6b45aaad1b3d16b76c775b0ec37591 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 19 Apr 2021 14:55:41 +0200 Subject: [PATCH 2/3] add changelog --- changelog/unreleased/config-parsing-run-subcommand.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/config-parsing-run-subcommand.md diff --git a/changelog/unreleased/config-parsing-run-subcommand.md b/changelog/unreleased/config-parsing-run-subcommand.md new file mode 100644 index 00000000000..7f84f037616 --- /dev/null +++ b/changelog/unreleased/config-parsing-run-subcommand.md @@ -0,0 +1,5 @@ +Enhancement: Parse config on supervised mode with run subcommand + +Currenntly it is not possible to parse a single config file from an extension when running on supervised mode. + +https://github.com/owncloud/ocis/pull/1931 From 60280a3f2822fd6ad67b1bbdf09c2bea101da053 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Tue, 20 Apr 2021 14:55:48 +0200 Subject: [PATCH 3/3] refactor and cleanup a bit --- ocis-pkg/config/config.go | 3 +++ ocis/pkg/runtime/service/service.go | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index 5b0ddfcf435..b6a652e6096 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -76,6 +76,9 @@ type Runtime struct { // Config combines all available configuration parts. type Config struct { + // Mode is mostly used whenever we need to run an extension. The technical debt this introduces is in regards of + // what it does. Supervised (0) loads configuration from a unified config file because of known limitations of Viper; whereas + // Unsupervised (1) MUST parse config from all known sources. Mode Mode File string diff --git a/ocis/pkg/runtime/service/service.go b/ocis/pkg/runtime/service/service.go index b0a5f1fabfb..cfab669058e 100644 --- a/ocis/pkg/runtime/service/service.go +++ b/ocis/pkg/runtime/service/service.go @@ -114,12 +114,18 @@ func NewService(options ...Option) (*Service, error) { // Start an rpc service. By default the package scope Start will run all default extensions to provide with a working // oCIS instance. func Start(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...) if err != nil { return err } + // notify goroutines that they are running on supervised mode + s.cfg.Mode = ociscfg.SUPERVISED + setMicroLogger() // Start creates its own supervisor. Running services under `ocis server` will create its own supervision tree. @@ -129,15 +135,12 @@ func Start(o ...Option) error { }, }) - // reva storages have their own logging. For consistency sake the top level logging will be cascade to reva. + // reva storages have their own logging. For consistency sake the top level logging will cascade to reva. s.cfg.Storage.Log.Color = s.cfg.Log.Color s.cfg.Storage.Log.Level = s.cfg.Log.Level s.cfg.Storage.Log.Pretty = s.cfg.Log.Pretty s.cfg.Storage.Log.File = s.cfg.Log.File - // notify goroutines that they are running on supervised mode - s.cfg.Mode = ociscfg.SUPERVISED - if err := rpc.Register(s); err != nil { if s != nil { s.Log.Fatal().Err(err) @@ -193,8 +196,12 @@ func Start(o ...Option) error { // Start indicates the Service Controller to start a new supervised service as an OS thread. func (s *Service) Start(name string, reply *int) error { + // RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different + // machine, the configuration needs to be present in the given machine. RPC does not yet allow providing a config + // during transport. + s.cfg.Mode = ociscfg.UNSUPERVISED + swap := deepcopy.Copy(s.cfg) - swap.(*ociscfg.Config).Mode = ociscfg.UNSUPERVISED if _, ok := s.ServicesRegistry[name]; ok { *reply = 0 s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config))))