mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	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:
		| @@ -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 | ||||
| ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user