mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-16 18:38:52 -07:00
37 lines
669 B
Go
37 lines
669 B
Go
|
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() {
|
||
|
for range Reload {
|
||
|
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
|
||
|
}
|