Skip to content

Commit

Permalink
Properly kill upgrade echo instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Irfan Habib committed Oct 19, 2017
1 parent b077b05 commit 48a8095
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions components/app-core/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -446,33 +447,30 @@ func start(config interfaces.PortalConfig, p *portalProxy, addSetupMiddleware *s
p.registerRoutes(e, addSetupMiddleware)
}

var engine *standard.Server
address := config.TLSAddress
if config.HTTPS {
certFile, certKeyFile, err := detectTLSCert(config)
if err != nil {
return err
}

address := config.TLSAddress
log.Infof("Starting HTTPS Server at address: %s", address)
engine := standard.WithTLS(address, certFile, certKeyFile)
if isUpgrade {
go stopEchoWhenUpgraded(e)
}
engine = standard.WithTLS(address, certFile, certKeyFile)

engineErr := e.Run(engine)
if engineErr != nil {
log.Warnf("Failed to start HTTPS server", engineErr)
}
} else {
address := config.TLSAddress
log.Infof("Starting HTTP Server at address: %s", address)
engine := standard.New(address)
if isUpgrade {
go stopEchoWhenUpgraded(e)
}
engineErr := e.Run(engine)
if engineErr != nil {
log.Warnf("Failed to start HTTP server", engineErr)
engine = standard.New(address)
}

if isUpgrade {
go stopEchoWhenUpgraded(engine)
}

engineErr := e.Run(engine)
if engineErr != nil {
engineErrStr := fmt.Sprintf("%s", engineErr)
if !strings.Contains(engineErrStr, "Server closed") {
log.Warnf("Failed to start HTTP/S server", engineErr)
}
}

Expand Down Expand Up @@ -652,11 +650,10 @@ func isConsoleUpgrading() bool {
return false
}

func stopEchoWhenUpgraded(e *echo.Echo) {
func stopEchoWhenUpgraded(e *standard.Server) {
for isConsoleUpgrading() {
time.Sleep(1 * time.Second)
}
log.Info("Console upgrade has completed! Shutting down Upgrade Echo instance")
e.Stop()

e.Close()
}

0 comments on commit 48a8095

Please sign in to comment.