diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index 0a7a2fd6cd..3b854d587f 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -10,6 +10,7 @@ import ( idp "github.com/owncloud/ocis/idp/pkg/command" ocs "github.com/owncloud/ocis/ocs/pkg/command" onlyoffice "github.com/owncloud/ocis/onlyoffice/pkg/command" + proxy "github.com/owncloud/ocis/proxy/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" "github.com/thejerf/suture" @@ -120,6 +121,7 @@ func (r *Runtime) Start() error { 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))) + addServiceToken("proxy", supervisor.Add(proxy.NewSutureService(globalCtx, r.c.Proxy))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/proxy/cmd/proxy/main.go b/proxy/cmd/proxy/main.go index 115f1b00f6..fbc6a6d744 100644 --- a/proxy/cmd/proxy/main.go +++ b/proxy/cmd/proxy/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/proxy/pkg/command" + "github.com/owncloud/ocis/proxy/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/proxy/pkg/command/root.go b/proxy/pkg/command/root.go index 906ccaa701..7fd5c6461b 100644 --- a/proxy/pkg/command/root.go +++ b/proxy/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-proxy command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-proxy", Version: version.String, @@ -109,3 +108,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/proxy/pkg/command/server.go b/proxy/pkg/command/server.go index bff16286a5..3c4b6e96df 100644 --- a/proxy/pkg/command/server.go +++ b/proxy/pkg/command/server.go @@ -45,7 +45,7 @@ func Server(cfg *config.Config) *cli.Command { return &cli.Command{ Name: "server", Usage: "Start integrated server", - Flags: flagset.ServerWithConfig(cfg), + Flags: append(flagset.ServerWithConfig(cfg), flagset.RootWithConfig(cfg)...), Before: func(ctx *cli.Context) error { if cfg.HTTP.Root != "/" { cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/") @@ -176,8 +176,6 @@ func Server(cfg *config.Config) *cli.Command { proxyHTTP.Context(ctx), proxyHTTP.Config(cfg), proxyHTTP.Metrics(metrics), - proxyHTTP.Flags(flagset.RootWithConfig(config.New())), - proxyHTTP.Flags(flagset.ServerWithConfig(config.New())), proxyHTTP.Middlewares(loadMiddlewares(ctx, logger, cfg)), ) diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index 29575c8ad1..b875757b6d 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -119,6 +121,8 @@ type Config struct { AutoprovisionAccounts bool EnableBasicAuth bool InsecureBackends bool + + Context context.Context } // OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request diff --git a/proxy/pkg/flagset/flagset.go b/proxy/pkg/flagset/flagset.go index 83f73fdda4..ca67c7b8a7 100644 --- a/proxy/pkg/flagset/flagset.go +++ b/proxy/pkg/flagset/flagset.go @@ -10,23 +10,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"PROXY_LOG_LEVEL"}, + EnvVars: []string{"PROXY_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", - Value: true, Usage: "Enable pretty logging", - EnvVars: []string{"PROXY_LOG_PRETTY"}, + EnvVars: []string{"PROXY_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", - Value: true, Usage: "Enable colored logging", - EnvVars: []string{"PROXY_LOG_COLOR"}, + EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, }