Merge pull request #45088 from corhere/make-apiserver-less-weird
api/server: delete Wait method
This commit is contained in:
commit
fb5df9722b
2 changed files with 9 additions and 24 deletions
|
@ -57,9 +57,8 @@ func (s *Server) Close() {
|
|||
}
|
||||
}
|
||||
|
||||
// serveAPI loops through all initialized servers and spawns goroutine
|
||||
// with Serve method for each. It sets createMux() as Handler also.
|
||||
func (s *Server) serveAPI() error {
|
||||
// Serve starts listening for inbound requests.
|
||||
func (s *Server) Serve() error {
|
||||
var chErrors = make(chan error, len(s.servers))
|
||||
for _, srv := range s.servers {
|
||||
srv.srv.Handler = s.createMux()
|
||||
|
@ -174,15 +173,3 @@ func (s *Server) createMux() *mux.Router {
|
|||
|
||||
return m
|
||||
}
|
||||
|
||||
// Wait blocks the server goroutine until it exits.
|
||||
// It sends an error message if there is any error during
|
||||
// the API execution.
|
||||
func (s *Server) Wait(waitChan chan error) {
|
||||
if err := s.serveAPI(); err != nil {
|
||||
logrus.Errorf("ServeAPI error: %v", err)
|
||||
waitChan <- err
|
||||
return
|
||||
}
|
||||
waitChan <- nil
|
||||
}
|
||||
|
|
|
@ -237,18 +237,16 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
|
||||
cli.setupConfigReloadTrap()
|
||||
|
||||
// The serve API routine never exits unless an error occurs
|
||||
// We need to start it as a goroutine and wait on it so
|
||||
// daemon doesn't exit
|
||||
serveAPIWait := make(chan error)
|
||||
go cli.api.Wait(serveAPIWait)
|
||||
|
||||
// after the daemon is done setting up we can notify systemd api
|
||||
notifyReady()
|
||||
|
||||
// Daemon is fully initialized and handling API traffic
|
||||
// Wait for serve API to complete
|
||||
errAPI := <-serveAPIWait
|
||||
// Daemon is fully initialized. Start handling API traffic
|
||||
// and wait for serve API to complete.
|
||||
errAPI := cli.api.Serve()
|
||||
if errAPI != nil {
|
||||
logrus.WithError(errAPI).Error("ServeAPI error")
|
||||
}
|
||||
|
||||
c.Cleanup()
|
||||
|
||||
// notify systemd that we're shutting down
|
||||
|
|
Loading…
Reference in a new issue