From ffcb57580f7c2b3ec6010ab67b389469b1748a4b Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 16 Jan 2021 12:58:02 +0100 Subject: [PATCH] cmd/syncthing: Provide early startup for config service (ref #7188) (#7285) --- cmd/syncthing/main.go | 15 +++++++++++++-- lib/syncthing/syncthing.go | 4 ---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 82fb26796..2ec4c6d1f 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -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 diff --git a/lib/syncthing/syncthing.go b/lib/syncthing/syncthing.go index 578be2f9b..23226c9aa 100644 --- a/lib/syncthing/syncthing.go +++ b/lib/syncthing/syncthing.go @@ -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)