refactoring: lots of refactoring around server shutdown flows, making sure process is terminated when background service has crashed

This commit is contained in:
Torkel Ödegaard
2018-05-02 14:14:42 +02:00
parent 053c2039bb
commit d04ad835e2
3 changed files with 33 additions and 53 deletions

View File

@ -64,7 +64,7 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
hs.streamManager.Run(ctx)
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
hs.log.Info("Initializing HTTP Server", "address", listenAddr, "protocol", setting.Protocol, "subUrl", setting.AppSubUrl, "socket", setting.SocketPath)
hs.log.Info("HTTP Server Listen", "address", listenAddr, "protocol", setting.Protocol, "subUrl", setting.AppSubUrl, "socket", setting.SocketPath)
hs.httpSrv = &http.Server{Addr: listenAddr, Handler: hs.macaron}
@ -74,7 +74,6 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
if err := hs.httpSrv.Shutdown(context.Background()); err != nil {
hs.log.Error("Failed to shutdown server", "error", err)
}
hs.log.Info("Stopped HTTP Server")
}()
switch setting.Protocol {
@ -113,12 +112,6 @@ func (hs *HTTPServer) Run(ctx context.Context) error {
return err
}
func (hs *HTTPServer) Shutdown(ctx context.Context) error {
err := hs.httpSrv.Shutdown(ctx)
hs.log.Info("Stopped HTTP server")
return err
}
func (hs *HTTPServer) listenAndServeTLS(certfile, keyfile string) error {
if certfile == "" {
return fmt.Errorf("cert_file cannot be empty when using HTTPS")