diff options
Diffstat (limited to 'plugin/file/setup.go')
-rw-r--r-- | plugin/file/setup.go | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/plugin/file/setup.go b/plugin/file/setup.go index c1dc853d6..ed19aedfe 100644 --- a/plugin/file/setup.go +++ b/plugin/file/setup.go @@ -8,8 +8,8 @@ import ( "github.com/coredns/caddy" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" - "github.com/coredns/coredns/plugin/pkg/parse" "github.com/coredns/coredns/plugin/pkg/upstream" + "github.com/coredns/coredns/plugin/transfer" ) func init() { plugin.Register("file", setup) } @@ -20,26 +20,43 @@ func setup(c *caddy.Controller) error { return plugin.Error("file", err) } - // Add startup functions to notify the master(s). + f := File{Zones: zones} + // get the transfer plugin, so we can send notifies and send notifies on startup as well. + c.OnStartup(func() error { + t := dnsserver.GetConfig(c).Handler("transfer") + if t == nil { + return nil + } + f.transfer = t.(*transfer.Transfer) // if found this must be OK. + for _, n := range zones.Names { + f.transfer.Notify(n) + } + return nil + }) + + c.OnRestartFailed(func() error { + t := dnsserver.GetConfig(c).Handler("transfer") + if t == nil { + return nil + } + for _, n := range zones.Names { + f.transfer.Notify(n) + } + return nil + }) + for _, n := range zones.Names { z := zones.Z[n] + c.OnShutdown(z.OnShutdown) c.OnStartup(func() error { - z.StartupOnce.Do(func() { - if len(z.TransferTo) > 0 { - z.Notify() - } - z.Reload() - }) + z.StartupOnce.Do(func() { z.Reload(f.transfer) }) return nil }) } - for _, n := range zones.Names { - z := zones.Z[n] - c.OnShutdown(z.OnShutdown) - } dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler { - return File{Next: next, Zones: zones} + f.Next = next + return f }) return nil @@ -92,24 +109,14 @@ func fileParse(c *caddy.Controller) (Zones, error) { names = append(names, origins[i]) } - t := []string{} - var e error - for c.NextBlock() { switch c.Val() { - case "transfer": - t, _, e = parse.Transfer(c, false) - if e != nil { - return Zones{}, e - } - case "reload": d, err := time.ParseDuration(c.RemainingArgs()[0]) if err != nil { return Zones{}, plugin.Error("file", err) } reload = d - case "upstream": // remove soon c.RemainingArgs() @@ -117,12 +124,6 @@ func fileParse(c *caddy.Controller) (Zones, error) { default: return Zones{}, c.Errf("unknown property '%s'", c.Val()) } - - for _, origin := range origins { - if t != nil { - z[origin].TransferTo = append(z[origin].TransferTo, t...) - } - } } } |