cmd/syncthing: Provide early startup for config service (ref #7188) (#7285)

This commit is contained in:
Jakob Borg 2021-01-16 12:58:02 +01:00 committed by GitHub
parent abfbd13f17
commit ffcb57580f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -45,6 +45,7 @@ import (
"github.com/syncthing/syncthing/lib/upgrade"
"github.com/pkg/errors"
"github.com/thejerf/suture/v4"
)
const (
@ -602,16 +603,26 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
os.Exit(1)
}
evLogger := events.NewLogger()
ctx, cancel := context.WithCancel(context.Background())
go evLogger.Serve(ctx)
defer cancel()
// earlyService is a supervisor that runs the services needed for or
// before app startup; the event logger, and the config service.
spec := svcutil.SpecWithDebugLogger(l)
earlyService := suture.New("early", spec)
earlyService.ServeBackground(ctx)
evLogger := events.NewLogger()
earlyService.Add(evLogger)
cfgWrapper, err := syncthing.LoadConfigAtStartup(locations.Get(locations.ConfigFile), cert, evLogger, runtimeOptions.allowNewerConfig, noDefaultFolder)
if err != nil {
l.Warnln("Failed to initialize config:", err)
os.Exit(svcutil.ExitError.AsInt())
}
if cfgService, ok := cfgWrapper.(suture.Service); ok {
earlyService.Add(cfgService)
}
// Candidate builds should auto upgrade. Make sure the option is set,
// unless we are in a build where it's disabled or the STNOUPGRADE

View File

@ -121,10 +121,6 @@ func (a *App) Start() error {
}
func (a *App) startup() error {
if cfgService, ok := a.cfg.(suture.Service); ok {
a.mainService.Add(cfgService)
}
a.mainService.Add(ur.NewFailureHandler(a.cfg, a.evLogger))
a.mainService.Add(a.ll)