WIP -- single binary -- works, replies to DNS, but need to check what got broken

This commit is contained in:
Eugene Bujak
2018-10-11 20:52:23 +03:00
parent 838406353b
commit bad88961e9
6 changed files with 174 additions and 175 deletions

View File

@@ -185,6 +185,10 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
})
}
onceHook.Do(func() {
caddy.RegisterEventHook("dnsfilter-reload", hook)
})
p.upstream, err = upstream.New(nil)
if err != nil {
return nil, err
@@ -573,4 +577,5 @@ func (p *plug) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
// Name returns name of the plugin as seen in Corefile and plugin.cfg
func (p *plug) Name() string { return "dnsfilter" }
var onceHook sync.Once
var onceQueryLog sync.Once

39
coredns_plugin/reload.go Normal file
View File

@@ -0,0 +1,39 @@
package dnsfilter
import (
"log"
"github.com/mholt/caddy"
)
var Reload = make(chan bool)
func hook(event caddy.EventName, info interface{}) error {
if event != caddy.InstanceStartupEvent {
return nil
}
// this should be an instance. ok to panic if not
instance := info.(*caddy.Instance)
go func() {
trace("Will wait for Reload channel")
for range Reload {
trace("Got message on Reload, restarting coredns")
corefile, err := caddy.LoadCaddyfile(instance.Caddyfile().ServerType())
if err != nil {
continue
}
_, err = instance.Restart(corefile)
if err != nil {
log.Printf("Corefile changed but reload failed: %s", err)
continue
}
// hook will be called again from new instance
return
}
}()
return nil
}