coredns reload -> dnsServer.Reconfigure()

This commit is contained in:
Eugene Bujak 2018-11-28 18:57:20 +03:00
parent 9d87ae95e6
commit 9c4b791621
2 changed files with 26 additions and 13 deletions

View File

@ -38,17 +38,13 @@ var client = &http.Client{
// -------------------
// coredns run control
// -------------------
func tellCoreDNSToReload() {
corednsplugin.Reload <- true
}
func writeAllConfigsAndReloadCoreDNS() error {
err := writeAllConfigs()
if err != nil {
log.Printf("Couldn't write all configs: %s", err)
return err
}
tellCoreDNSToReload()
reconfigureDNSServer()
return nil
}
@ -155,7 +151,7 @@ func handleSetUpstreamDNS(w http.ResponseWriter, r *http.Request) {
http.Error(w, errorText, http.StatusInternalServerError)
return
}
tellCoreDNSToReload()
reconfigureDNSServer()
_, err = fmt.Fprintf(w, "OK %d servers\n", len(hosts))
if err != nil {
errorText := fmt.Sprintf("Couldn't write body: %s", err)
@ -386,7 +382,7 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) {
return
}
tellCoreDNSToReload()
reconfigureDNSServer()
_, err = fmt.Fprintf(w, "OK %d rules\n", filter.RulesCount)
if err != nil {
@ -571,7 +567,7 @@ func refreshFiltersIfNeccessary(force bool) int {
config.Unlock()
if updateCount > 0 {
tellCoreDNSToReload()
reconfigureDNSServer()
}
return updateCount
}

View File

@ -15,11 +15,7 @@ func isRunning() bool {
return dnsServer.IsRunning()
}
func startDNSServer() error {
if isRunning() {
return fmt.Errorf("Unable to start coreDNS: Already running")
}
func generateServerConfig() dnsforward.ServerConfig {
filters := []dnsforward.Filter{}
for _, filter := range config.Filters {
filters = append(filters, dnsforward.Filter{
@ -43,7 +39,15 @@ func startDNSServer() error {
}
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
}
return newconfig
}
func startDNSServer() error {
if isRunning() {
return fmt.Errorf("Unable to start forwarding DNS server: Already running")
}
newconfig := generateServerConfig()
err := dnsServer.Start(&newconfig)
if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
@ -51,3 +55,16 @@ func startDNSServer() error {
return nil
}
func reconfigureDNSServer() error {
if !isRunning() {
return fmt.Errorf("Refusing to reconfigure forwarding DNS server: not running")
}
err := dnsServer.Reconfigure(generateServerConfig())
if err != nil {
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
}
return nil
}