Reload zone when a write is detected (#122)

Zone reloading
This commit is contained in:
Miek Gieben
2016-04-15 14:26:27 +01:00
parent 29ad957a9d
commit c9d8a57ed6
10 changed files with 179 additions and 60 deletions

View File

@@ -16,18 +16,17 @@ func File(c *Controller) (middleware.Middleware, error) {
return nil, err
}
// Add startup functions to notify the master.
// Add startup functions to notify the master(s).
for _, n := range zones.Names {
if len(zones.Z[n].TransferTo) > 0 {
c.Startup = append(c.Startup, func() error {
zones.Z[n].StartupOnce.Do(func() {
if len(zones.Z[n].TransferTo) > 0 {
zones.Z[n].Notify()
}
})
return nil
c.Startup = append(c.Startup, func() error {
zones.Z[n].StartupOnce.Do(func() {
if len(zones.Z[n].TransferTo) > 0 {
zones.Z[n].Notify()
}
zones.Z[n].Reload(nil)
})
}
return nil
})
}
return func(next middleware.Handler) middleware.Handler {
@@ -67,17 +66,24 @@ func fileParse(c *Controller) (file.Zones, error) {
names = append(names, origins[i])
}
noReload := false
for c.NextBlock() {
t, _, e := parseTransfer(c)
if e != nil {
return file.Zones{}, e
}
switch c.Val() {
case "no_reload":
noReload = true
}
// discard from, here, maybe check and show log when we do?
for _, origin := range origins {
if t != nil {
z[origin].TransferTo = append(z[origin].TransferTo, t...)
}
z[origin].NoReload = noReload
}
}
}
}

View File

@@ -47,7 +47,7 @@ func secondaryParse(c *Controller) (file.Zones, error) {
}
for i, _ := range origins {
origins[i] = middleware.Host(origins[i]).Normalize()
z[origins[i]] = file.NewZone(origins[i])
z[origins[i]] = file.NewZone(origins[i], "stdin")
names = append(names, origins[i])
}