aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/file/setup.go')
-rw-r--r--plugin/file/setup.go59
1 files changed, 29 insertions, 30 deletions
diff --git a/plugin/file/setup.go b/plugin/file/setup.go
index 1309dcf85..44ecf2ca1 100644
--- a/plugin/file/setup.go
+++ b/plugin/file/setup.go
@@ -7,8 +7,8 @@ import (
"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"
"github.com/caddyserver/caddy"
)
@@ -21,43 +21,26 @@ func setup(c *caddy.Controller) error {
return plugin.Error("file", err)
}
- 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
- })
-
+ // Add startup functions to notify the master(s).
for _, n := range zones.Names {
z := zones.Z[n]
- c.OnShutdown(z.OnShutdown)
c.OnStartup(func() error {
- z.StartupOnce.Do(func() { z.Reload(f.transfer) })
+ z.StartupOnce.Do(func() {
+ if len(z.TransferTo) > 0 {
+ z.Notify()
+ }
+ z.Reload()
+ })
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 {
- f.Next = next
- return f
+ return File{Next: next, Zones: zones}
})
return nil
@@ -110,14 +93,24 @@ 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()
@@ -125,6 +118,12 @@ 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...)
+ }
+ }
}
}