MCPcopy
hub / github.com/coredns/coredns / onStartup

Method onStartup

plugin/ready/ready.go:38–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36const shutdownTimeout = 5 * time.Second
37
38func (rd *ready) onStartup() error {
39 ln, err := reuseport.Listen("tcp", rd.Addr)
40 if err != nil {
41 return err
42 }
43
44 rd.Lock()
45 rd.ln = ln
46 rd.mux = http.NewServeMux()
47 rd.done = true
48 rd.Unlock()
49
50 rd.mux.HandleFunc("/ready", func(w http.ResponseWriter, _ *http.Request) {
51 rd.Lock()
52 defer rd.Unlock()
53 if !rd.done {
54 w.WriteHeader(http.StatusServiceUnavailable)
55 io.WriteString(w, "Shutting down")
56 return
57 }
58 ready, notReadyPlugins := plugins.Ready()
59 if ready {
60 w.WriteHeader(http.StatusOK)
61 io.WriteString(w, http.StatusText(http.StatusOK))
62 return
63 }
64 log.Infof("Plugins not ready: %q", notReadyPlugins)
65 w.WriteHeader(http.StatusServiceUnavailable)
66 io.WriteString(w, notReadyPlugins)
67 })
68
69 rd.srv = &http.Server{
70 Handler: rd.mux,
71 ReadTimeout: 5 * time.Second,
72 WriteTimeout: 5 * time.Second,
73 IdleTimeout: 5 * time.Second,
74 }
75
76 go func() { rd.srv.Serve(rd.ln) }()
77
78 return nil
79}
80
81func (rd *ready) onFinalShutdown() error {
82 rd.Lock()

Callers 2

TestReadyFunction · 0.95
TestReady_ContinuouslyFunction · 0.95

Calls 4

ListenFunction · 0.92
InfofFunction · 0.92
ReadyMethod · 0.65
ServeMethod · 0.45

Tested by 2

TestReadyFunction · 0.76
TestReady_ContinuouslyFunction · 0.76