Make middleware survive a restart (#142)

Make middleware that sets up a (http) handler survive a graceful
restart. We calls the middleware's Shutdown function(s). If restart
fails the Start function is called again.

* middleware/health: OK
* middleware/pprof: OK
* middleware/metrics: OK

All restart OK.
This commit is contained in:
Miek Gieben 2016-04-29 07:28:35 +01:00
parent a1478f891d
commit 9e9d72655d
10 changed files with 132 additions and 54 deletions

View file

@ -68,4 +68,26 @@ func executeShutdownCallbacks(signame string) (exitCode int) {
return
}
var shutdownCallbacksOnce sync.Once
// executeStartupCallbacks executes the startup callbacks as initiated
// by signame. This is used when on restart when the child failed to start and
// all middleware executed their shutdown functions
func executeStartupCallbacks(signame string) (exitCode int) {
startupCallbacksOnce.Do(func() {
serversMu.Lock()
errs := server.StartupCallbacks(servers)
serversMu.Unlock()
if len(errs) > 0 {
for _, err := range errs {
log.Printf("[ERROR] %s shutdown: %v", signame, err)
}
exitCode = 1
}
})
return
}
var (
shutdownCallbacksOnce sync.Once
startupCallbacksOnce sync.Once
)