@@ -1,7 +1,10 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
|
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config"
|
"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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
// Prefer the in-memory registry as the default when running in single-binary mode
|
// Prefer the in-memory registry as the default when running in single-binary mode
|
||||||
r := runtime.New(cfg)
|
r := runtime.New(cfg)
|
||||||
return r.Start()
|
return r.Start(c.Context)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/config"
|
"github.com/owncloud/ocis/v2/ocis-pkg/config"
|
||||||
"github.com/owncloud/ocis/v2/ocis/pkg/runtime/service"
|
"github.com/owncloud/ocis/v2/ocis/pkg/runtime/service"
|
||||||
)
|
)
|
||||||
@@ -18,6 +20,6 @@ func New(cfg *config.Config) Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start rpc runtime
|
// Start rpc runtime
|
||||||
func (r *Runtime) Start() error {
|
func (r *Runtime) Start(ctx context.Context) error {
|
||||||
return service.Start(service.WithConfig(r.c))
|
return service.Start(ctx, service.WithConfig(r.c))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ type Service struct {
|
|||||||
// calls are done explicitly to loadFromEnv().
|
// calls are done explicitly to loadFromEnv().
|
||||||
// Since this is the public constructor, options need to be added, at the moment only logging options
|
// 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.
|
// 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()
|
opts := NewOptions()
|
||||||
|
|
||||||
for _, f := range options {
|
for _, f := range options {
|
||||||
@@ -109,7 +109,7 @@ func NewService(options ...Option) (*Service, error) {
|
|||||||
log.Level(opts.Config.Log.Level),
|
log.Level(opts.Config.Log.Level),
|
||||||
)
|
)
|
||||||
|
|
||||||
globalCtx, cancelGlobal := context.WithCancel(context.Background())
|
globalCtx, cancelGlobal := context.WithCancel(ctx)
|
||||||
|
|
||||||
s := &Service{
|
s := &Service{
|
||||||
Services: make([]serviceFuncMap, len(_waitFuncs)),
|
Services: make([]serviceFuncMap, len(_waitFuncs)),
|
||||||
@@ -352,12 +352,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
|
// Start a rpc service. By default, the package scope Start will run all default services to provide with a working
|
||||||
// oCIS instance.
|
// 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
|
// 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.
|
// from the caller, the previous statement holds truth.
|
||||||
|
|
||||||
// prepare a new rpc Service struct.
|
// prepare a new rpc Service struct.
|
||||||
s, err := NewService(o...)
|
s, err := NewService(ctx, o...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/v2/services/gateway/pkg/command"
|
"github.com/owncloud/ocis/v2/services/gateway/pkg/command"
|
||||||
"github.com/owncloud/ocis/v2/services/gateway/pkg/config/defaults"
|
"github.com/owncloud/ocis/v2/services/gateway/pkg/config/defaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,5 @@ func Execute(cfg *config.Config) error {
|
|||||||
Commands: GetCommands(cfg),
|
Commands: GetCommands(cfg),
|
||||||
})
|
})
|
||||||
|
|
||||||
return app.Run(os.Args)
|
return app.RunContext(cfg.Context, os.Args)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gr := run.Group{}
|
gr := run.Group{}
|
||||||
ctx, cancel := defineContext(cfg)
|
ctx, cancel := context.WithCancel(c.Context)
|
||||||
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -51,7 +51,9 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
runtime.WithRegistry(reg),
|
runtime.WithRegistry(reg),
|
||||||
runtime.WithTraceProvider(traceProvider),
|
runtime.WithTraceProvider(traceProvider),
|
||||||
)
|
)
|
||||||
|
logger.Info().
|
||||||
|
Str("server", cfg.Service.Name).
|
||||||
|
Msg("reva runtime exited")
|
||||||
return nil
|
return nil
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
logger.Error().
|
logger.Error().
|
||||||
@@ -60,7 +62,6 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
Msg("Shutting down server")
|
Msg("Shutting down server")
|
||||||
|
|
||||||
cancel()
|
cancel()
|
||||||
os.Exit(1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
debugServer, err := debug.Server(
|
debugServer, err := debug.Server(
|
||||||
@@ -74,6 +75,9 @@ func Server(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
logger.Info().
|
||||||
|
Str("server", cfg.Service.Name).
|
||||||
|
Msg("Shutting down debug erver")
|
||||||
cancel()
|
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)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user