lib/syncthing: Also cleanup on startup error (#6926)

This commit is contained in:
Simon Frei
2020-08-27 15:52:51 +02:00
committed by GitHub
parent 0941ce76b7
commit 3f0eba388c
2 changed files with 24 additions and 12 deletions
+15 -11
View File
@@ -110,16 +110,6 @@ func New(cfg config.Wrapper, dbBackend backend.Backend, evLogger events.Logger,
// e.g. the API is ready for use.
// Must be called once only.
func (a *App) Start() error {
if err := a.startup(); err != nil {
a.stopWithErr(ExitError, err)
return err
}
a.stopped = make(chan struct{})
go a.run()
return nil
}
func (a *App) startup() error {
// Create a main service manager. We'll add things to this as we go along.
// We want any logging it does to go through our log system.
a.mainService = suture.New("main", suture.Spec{
@@ -128,8 +118,22 @@ func (a *App) startup() error {
},
PassThroughPanics: true,
})
a.mainService.Add(a.ll)
// Start the supervisor and wait for it to stop to handle cleanup.
a.stopped = make(chan struct{})
a.mainService.ServeBackground()
go a.run()
if err := a.startup(); err != nil {
a.stopWithErr(ExitError, err)
return err
}
return nil
}
func (a *App) startup() error {
a.mainService.Add(a.ll)
if a.opts.AuditWriter != nil {
a.mainService.Add(newAuditService(a.opts.AuditWriter, a.evLogger))