From f7917bf76040116c62ee87c433df4b455bd326c9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 13:26:49 +0100 Subject: [PATCH] add onlyoffice --- ocis/pkg/runtime/runtime.go | 10 ++++---- onlyoffice/cmd/onlyoffice/main.go | 3 ++- onlyoffice/pkg/command/root.go | 33 +++++++++++++++++++++++--- onlyoffice/pkg/command/server.go | 2 -- onlyoffice/pkg/config/config.go | 4 ++++ onlyoffice/pkg/flagset/flagset.go | 9 +++---- storage/pkg/command/storagemetadata.go | 2 +- 7 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index efcf0be69d..0a7a2fd6cd 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -9,6 +9,7 @@ import ( glauth "github.com/owncloud/ocis/glauth/pkg/command" idp "github.com/owncloud/ocis/idp/pkg/command" ocs "github.com/owncloud/ocis/ocs/pkg/command" + onlyoffice "github.com/owncloud/ocis/onlyoffice/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" "github.com/thejerf/suture" @@ -35,10 +36,10 @@ var ( // Extensions are oCIS extension services Extensions = []string{ - "glauth", // done - "idp", // done - "ocs", // done - "onlyoffice", + "glauth", // done + "idp", // done + "ocs", // done + "onlyoffice", // done "proxy", "settings", // done "store", @@ -118,6 +119,7 @@ func (r *Runtime) Start() error { addServiceToken("glauth", supervisor.Add(glauth.NewSutureService(globalCtx, r.c.GLAuth))) addServiceToken("idp", supervisor.Add(idp.NewSutureService(globalCtx, r.c.IDP))) addServiceToken("ocs", supervisor.Add(ocs.NewSutureService(globalCtx, r.c.OCS))) + addServiceToken("onlyoffice", supervisor.Add(onlyoffice.NewSutureService(globalCtx, r.c.Onlyoffice))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/onlyoffice/cmd/onlyoffice/main.go b/onlyoffice/cmd/onlyoffice/main.go index 8f1162bd34..75c7edf4ad 100644 --- a/onlyoffice/cmd/onlyoffice/main.go +++ b/onlyoffice/cmd/onlyoffice/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/onlyoffice/pkg/command" + "github.com/owncloud/ocis/onlyoffice/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/onlyoffice/pkg/command/root.go b/onlyoffice/pkg/command/root.go index 33951f2314..b128a90578 100644 --- a/onlyoffice/pkg/command/root.go +++ b/onlyoffice/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "context" "os" "strings" @@ -13,9 +14,7 @@ import ( ) // Execute is the entry point for the ocis-onlyoffice command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "onlyoffice", Version: version.String, @@ -106,3 +105,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the onlyoffice command to be embedded and supervised by a suture supervisor tree. +type SutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewSutureService creates a new onlyoffice.SutureService +func NewSutureService(ctx context.Context, cfg *config.Config) SutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx // propagate the context down to the go-micro services. + return SutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s SutureService) Serve() { + if err := Execute(s.cfg); err != nil { + return + } +} + +func (s SutureService) Stop() { + s.cancel() +} diff --git a/onlyoffice/pkg/command/server.go b/onlyoffice/pkg/command/server.go index c8b19904fd..d8d0d7dbd1 100644 --- a/onlyoffice/pkg/command/server.go +++ b/onlyoffice/pkg/command/server.go @@ -138,8 +138,6 @@ func Server(cfg *config.Config) *cli.Command { http.Context(ctx), http.Config(cfg), http.Metrics(metrics), - http.Flags(flagset.RootWithConfig(config.New())), - http.Flags(flagset.ServerWithConfig(config.New())), ) if err != nil { diff --git a/onlyoffice/pkg/config/config.go b/onlyoffice/pkg/config/config.go index df091801b0..1f512a1234 100644 --- a/onlyoffice/pkg/config/config.go +++ b/onlyoffice/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -40,6 +42,8 @@ type Config struct { HTTP HTTP Tracing Tracing Asset Asset + + Context context.Context } // Asset defines the available asset configuration. diff --git a/onlyoffice/pkg/flagset/flagset.go b/onlyoffice/pkg/flagset/flagset.go index c5ac1f9aea..d7bd7707f0 100644 --- a/onlyoffice/pkg/flagset/flagset.go +++ b/onlyoffice/pkg/flagset/flagset.go @@ -17,23 +17,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"ONLYOFFICE_LOG_LEVEL"}, + EnvVars: []string{"ONLYOFFICE_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", - Value: true, Usage: "Enable pretty logging", - EnvVars: []string{"ONLYOFFICE_LOG_PRETTY"}, + EnvVars: []string{"ONLYOFFICE_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", - Value: true, Usage: "Enable colored logging", - EnvVars: []string{"ONLYOFFICE_LOG_COLOR"}, + EnvVars: []string{"ONLYOFFICE_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, } diff --git a/storage/pkg/command/storagemetadata.go b/storage/pkg/command/storagemetadata.go index 7199c6682a..ff258482ea 100644 --- a/storage/pkg/command/storagemetadata.go +++ b/storage/pkg/command/storagemetadata.go @@ -220,7 +220,7 @@ func StorageMetadata(cfg *config.Config) *cli.Command { } } -// SutureService allows for the settings command to be embedded and supervised by a suture supervisor tree. +// SutureService allows for the storage-metadata command to be embedded and supervised by a suture supervisor tree. type SutureService struct { ctx context.Context cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.