aboutsummaryrefslogtreecommitdiff
path: root/server/server.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-04-29 07:28:35 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-04-29 07:28:35 +0100
commit9e9d72655d865f2d136ad3b0439735cde53b679f (patch)
treef0c365ffb5fbe9599374ab2551463d610f79ebd6 /server/server.go
parenta1478f891dd6849835973720df6b5651a8ea88fd (diff)
downloadcoredns-9e9d72655d865f2d136ad3b0439735cde53b679f.tar.gz
coredns-9e9d72655d865f2d136ad3b0439735cde53b679f.tar.zst
coredns-9e9d72655d865f2d136ad3b0439735cde53b679f.zip
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.
Diffstat (limited to 'server/server.go')
-rw-r--r--server/server.go41
1 files changed, 15 insertions, 26 deletions
diff --git a/server/server.go b/server/server.go
index 068a54a31..af5dd35e1 100644
--- a/server/server.go
+++ b/server/server.go
@@ -445,32 +445,6 @@ func (s *Server) RunFirstStartupFuncs() error {
return nil
}
-// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
-// connections. It's used by ListenAndServe and ListenAndServeTLS so
-// dead TCP connections (e.g. closing laptop mid-download) eventually
-// go away.
-//
-// Borrowed from the Go standard library.
-type tcpKeepAliveListener struct {
- *net.TCPListener
-}
-
-// Accept accepts the connection with a keep-alive enabled.
-func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
- tc, err := ln.AcceptTCP()
- if err != nil {
- return
- }
- tc.SetKeepAlive(true)
- tc.SetKeepAlivePeriod(3 * time.Minute)
- return tc, nil
-}
-
-// File implements ListenerFile; returns the underlying file of the listener.
-func (ln tcpKeepAliveListener) File() (*os.File, error) {
- return ln.TCPListener.File()
-}
-
// ShutdownCallbacks executes all the shutdown callbacks
// for all the virtualhosts in servers, and returns all the
// errors generated during their execution. In other words,
@@ -493,6 +467,21 @@ func ShutdownCallbacks(servers []*Server) []error {
return errs
}
+func StartupCallbacks(servers []*Server) []error {
+ var errs []error
+ for _, s := range servers {
+ for _, zone := range s.zones {
+ for _, startupFunc := range zone.config.Startup {
+ err := startupFunc()
+ if err != nil {
+ errs = append(errs, err)
+ }
+ }
+ }
+ }
+ return errs
+}
+
func RcodeNoClientWrite(rcode int) bool {
switch rcode {
case dns.RcodeServerFailure: