update commands when running in supervised mode

This commit is contained in:
A.Unger
2021-03-10 11:10:46 +01:00
parent 25909d5923
commit 4e37d4a2f6
72 changed files with 1547 additions and 803 deletions

View File

@@ -5,8 +5,6 @@ import (
"os"
"strings"
"github.com/thejerf/suture"
"github.com/micro/cli/v2"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
@@ -14,6 +12,7 @@ import (
"github.com/owncloud/ocis/settings/pkg/flagset"
"github.com/owncloud/ocis/settings/pkg/version"
"github.com/spf13/viper"
"github.com/thejerf/suture"
)
// Execute is the entry point for the ocis-settings command.
@@ -122,6 +121,9 @@ type SutureService struct {
func NewSutureService(ctx context.Context, cfg *ociscfg.Config) suture.Service {
sctx, cancel := context.WithCancel(ctx)
cfg.Settings.Context = sctx
if cfg.Mode == 0 {
cfg.Settings.Supervised = true
}
return SutureService{
ctx: sctx,
cancel: cancel,

View File

@@ -2,11 +2,11 @@ package command
import (
"context"
"os"
"os/signal"
"strings"
"time"
"github.com/owncloud/ocis/ocis-pkg/sync"
"github.com/owncloud/ocis/settings/pkg/metrics"
"contrib.go.opencensus.io/exporter/jaeger"
@@ -130,18 +130,16 @@ func Server(cfg *config.Config) *cli.Command {
}
var (
gr = run.Group{}
ctx = cfg.Context
cancel context.CancelFunc
mtrcs = 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)
}()
mtrcs = metrics.New()
)
if ctx == nil {
ctx, cancel = context.WithCancel(context.Background())
} else {
ctx, cancel = context.WithCancel(cfg.Context)
}
defer cancel()
mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1)
@@ -190,20 +188,14 @@ func Server(cfg *config.Config) *cli.Command {
)
if err != nil {
logger.Error().
Err(err).
Str("server", "debug").
Msg("Failed to initialize server")
logger.Error().Err(err).Str("server", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(server.ListenAndServe, func(_ error) {
ctx, timeout := context.WithTimeout(ctx, 5*time.Second)
defer timeout()
defer cancel()
if err := server.Shutdown(ctx); err != nil {
logger.Error().
Err(err).
@@ -217,19 +209,8 @@ func Server(cfg *config.Config) *cli.Command {
})
}
{
stop := make(chan os.Signal, 1)
gr.Add(func() error {
signal.Notify(stop, os.Interrupt)
<-stop
return nil
}, func(err error) {
close(stop)
cancel()
})
if !cfg.Supervised {
sync.Trap(&gr, cancel)
}
return gr.Run()

View File

@@ -69,7 +69,8 @@ type Config struct {
Asset Asset
TokenManager TokenManager
Context context.Context
Context context.Context
Supervised bool
}
// New initializes a new configuration with or without defaults.