mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Watch the entire directory
Instead of watching a single file watch the entire directory and catch the .Name from the event. On any event, just reload the damn thing. This also fixes the problem of loosing events when the inode changes.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware"
|
"github.com/miekg/coredns/middleware"
|
||||||
@@ -107,7 +108,7 @@ func (z *Zone) Reload(shutdown chan bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = watcher.Add(z.file)
|
err = watcher.Add(path.Dir(z.file))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -117,11 +118,7 @@ func (z *Zone) Reload(shutdown chan bool) error {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Rename == fsnotify.Rename {
|
if event.Name == z.file {
|
||||||
if err := watcher.Add(z.file); err != nil {
|
|
||||||
log.Printf("[ERROR] Failed to open `%s' for `%s': %v", z.file, z.origin, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
reader, err := os.Open(z.file)
|
reader, err := os.Open(z.file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERROR] Failed to open `%s' for `%s': %v", z.file, z.origin, err)
|
log.Printf("[ERROR] Failed to open `%s' for `%s': %v", z.file, z.origin, err)
|
||||||
@@ -139,7 +136,7 @@ func (z *Zone) Reload(shutdown chan bool) error {
|
|||||||
z.SIG = zone.SIG
|
z.SIG = zone.SIG
|
||||||
z.Tree = zone.Tree
|
z.Tree = zone.Tree
|
||||||
z.reloadMu.Unlock()
|
z.reloadMu.Unlock()
|
||||||
log.Printf("[INFO] Successfully reload zone `%s'", z.origin)
|
log.Printf("[INFO] Successfully reloaded zone `%s'", z.origin)
|
||||||
}
|
}
|
||||||
case <-shutdown:
|
case <-shutdown:
|
||||||
watcher.Close()
|
watcher.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user