Browse Source

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

Jakob Borg 5 năm trước cách đây
mục cha
commit
ffcb57580f
2 tập tin đã thay đổi với 13 bổ sung6 xóa
  1. 13 2
      cmd/syncthing/main.go
  2. 0 4
      lib/syncthing/syncthing.go

+ 13 - 2
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

+ 0 - 4
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)