diff --git a/plugin/etcd/etcd.go b/plugin/etcd/etcd.go index 077e490f1..a78673027 100644 --- a/plugin/etcd/etcd.go +++ b/plugin/etcd/etcd.go @@ -183,3 +183,11 @@ func (e *Etcd) TTL(kv *mvccpb.KeyValue, serv *msg.Service) uint32 { func shouldInclude(serv *msg.Service, qType uint16) bool { return (qType == dns.TypeTXT && serv.Text != "") || serv.Host != "" } + +// OnShutdown shuts down etcd client when caddy instance restart +func (e *Etcd) OnShutdown() error { + if e.Client != nil { + e.Client.Close() + } + return nil +} diff --git a/plugin/etcd/setup.go b/plugin/etcd/setup.go index ab6c4b798..68a1b7f42 100644 --- a/plugin/etcd/setup.go +++ b/plugin/etcd/setup.go @@ -21,6 +21,8 @@ func setup(c *caddy.Controller) error { return plugin.Error("etcd", err) } + c.OnShutdown(e.OnShutdown) + dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { e.Next = next return e