all: Get rid of fatal logging (#5537)
* cleanup Fatal in lib/config/config.go * cleanup Fatal in lib/config/folderconfiguration.go * cleanup Fatal in lib/model/model.go * cleanup Fatal in cmd/syncthing/monitor.go * cleanup Fatal in cmd/syncthing/main.go * cleanup Fatal in lib/api * remove Fatal methods from logger * lowercase in errors.Wrap * one less channel
This commit is contained in:
committed by
Audrius Butkevicius
parent
7a40c42e8b
commit
d5ff2c41dc
@@ -78,7 +78,8 @@ type apiService struct {
|
||||
stop chan struct{} // signals intentional stop
|
||||
configChanged chan struct{} // signals intentional listener close due to config change
|
||||
started chan string // signals startup complete by sending the listener address, for testing only
|
||||
startedOnce chan struct{} // the service has started successfully at least once
|
||||
startedOnce chan struct{} // the service has started at least once
|
||||
startupErr error
|
||||
cpu rater
|
||||
|
||||
guiErrors logger.Recorder
|
||||
@@ -174,6 +175,11 @@ func newAPIService(id protocol.DeviceID, cfg configIntf, httpsCertFile, httpsKey
|
||||
return service
|
||||
}
|
||||
|
||||
func (s *apiService) WaitForStart() error {
|
||||
<-s.startedOnce
|
||||
return s.startupErr
|
||||
}
|
||||
|
||||
func (s *apiService) getListener(guiCfg config.GUIConfiguration) (net.Listener, error) {
|
||||
cert, err := tls.LoadX509KeyPair(s.httpsCertFile, s.httpsKeyFile)
|
||||
if err != nil {
|
||||
@@ -236,14 +242,15 @@ func (s *apiService) Serve() {
|
||||
// We let this be a loud user-visible warning as it may be the only
|
||||
// indication they get that the GUI won't be available.
|
||||
l.Warnln("Starting API/GUI:", err)
|
||||
return
|
||||
|
||||
default:
|
||||
// This is during initialization. A failure here should be fatal
|
||||
// as there will be no way for the user to communicate with us
|
||||
// otherwise anyway.
|
||||
l.Fatalln("Starting API/GUI:", err)
|
||||
s.startupErr = err
|
||||
close(s.startedOnce)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if listener == nil {
|
||||
@@ -410,6 +417,19 @@ func (s *apiService) Serve() {
|
||||
}
|
||||
}
|
||||
|
||||
// Complete implements suture.IsCompletable, which signifies to the supervisor
|
||||
// whether to stop restarting the service.
|
||||
func (s *apiService) Complete() bool {
|
||||
select {
|
||||
case <-s.startedOnce:
|
||||
return s.startupErr != nil
|
||||
case <-s.stop:
|
||||
return true
|
||||
default:
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *apiService) Stop() {
|
||||
close(s.stop)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user