coredns reload -> dnsServer.Reconfigure()
This commit is contained in:
parent
9d87ae95e6
commit
9c4b791621
12
control.go
12
control.go
|
@ -38,17 +38,13 @@ var client = &http.Client{
|
||||||
// -------------------
|
// -------------------
|
||||||
// coredns run control
|
// coredns run control
|
||||||
// -------------------
|
// -------------------
|
||||||
func tellCoreDNSToReload() {
|
|
||||||
corednsplugin.Reload <- true
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeAllConfigsAndReloadCoreDNS() error {
|
func writeAllConfigsAndReloadCoreDNS() error {
|
||||||
err := writeAllConfigs()
|
err := writeAllConfigs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Couldn't write all configs: %s", err)
|
log.Printf("Couldn't write all configs: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tellCoreDNSToReload()
|
reconfigureDNSServer()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +151,7 @@ func handleSetUpstreamDNS(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, errorText, http.StatusInternalServerError)
|
http.Error(w, errorText, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tellCoreDNSToReload()
|
reconfigureDNSServer()
|
||||||
_, err = fmt.Fprintf(w, "OK %d servers\n", len(hosts))
|
_, err = fmt.Fprintf(w, "OK %d servers\n", len(hosts))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorText := fmt.Sprintf("Couldn't write body: %s", err)
|
errorText := fmt.Sprintf("Couldn't write body: %s", err)
|
||||||
|
@ -386,7 +382,7 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tellCoreDNSToReload()
|
reconfigureDNSServer()
|
||||||
|
|
||||||
_, err = fmt.Fprintf(w, "OK %d rules\n", filter.RulesCount)
|
_, err = fmt.Fprintf(w, "OK %d rules\n", filter.RulesCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -571,7 +567,7 @@ func refreshFiltersIfNeccessary(force bool) int {
|
||||||
config.Unlock()
|
config.Unlock()
|
||||||
|
|
||||||
if updateCount > 0 {
|
if updateCount > 0 {
|
||||||
tellCoreDNSToReload()
|
reconfigureDNSServer()
|
||||||
}
|
}
|
||||||
return updateCount
|
return updateCount
|
||||||
}
|
}
|
||||||
|
|
27
coredns.go
27
coredns.go
|
@ -15,11 +15,7 @@ func isRunning() bool {
|
||||||
return dnsServer.IsRunning()
|
return dnsServer.IsRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
func startDNSServer() error {
|
func generateServerConfig() dnsforward.ServerConfig {
|
||||||
if isRunning() {
|
|
||||||
return fmt.Errorf("Unable to start coreDNS: Already running")
|
|
||||||
}
|
|
||||||
|
|
||||||
filters := []dnsforward.Filter{}
|
filters := []dnsforward.Filter{}
|
||||||
for _, filter := range config.Filters {
|
for _, filter := range config.Filters {
|
||||||
filters = append(filters, dnsforward.Filter{
|
filters = append(filters, dnsforward.Filter{
|
||||||
|
@ -43,7 +39,15 @@ func startDNSServer() error {
|
||||||
}
|
}
|
||||||
newconfig.Upstreams = append(newconfig.Upstreams, upstream)
|
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)
|
err := dnsServer.Start(&newconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
|
@ -51,3 +55,16 @@ func startDNSServer() error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue