diff options
author | 2019-07-04 06:56:37 +0100 | |
---|---|---|
committer | 2019-07-04 13:56:37 +0800 | |
commit | 18304ce9b75a401ed510d270c013dc4fe6480420 (patch) | |
tree | 089fc37b837831cd06c8012d922b94033ce21d64 /plugin/file/setup.go | |
parent | f9fb9db1715e074c7549548e72f1d29d5ddc268f (diff) | |
download | coredns-18304ce9b75a401ed510d270c013dc4fe6480420.tar.gz coredns-18304ce9b75a401ed510d270c013dc4fe6480420.tar.zst coredns-18304ce9b75a401ed510d270c013dc4fe6480420.zip |
plugin/file: make non-existent file non-fatal (#2955)
* plugin/file: make non-existent file non-fatal
If the zone file being loaded doesn't exist *and* reload is enabled,
just wait the file to pop up in the normal Reload routine.
If reload is set to 0s; we keep this a fatal error on startup. Aslo fix
the ticker in z.Reload(): remove the per second ticks and just use the
reload interval for the ticker.
Brush up the documentation a bit as well.
Fixes: #2951
Signed-off-by: Miek Gieben <miek@miek.nl>
* Stickler and test compile
Signed-off-by: Miek Gieben <miek@miek.nl>
* Remove there too
Signed-off-by: Miek Gieben <miek@miek.nl>
* Cant README test these because zone files dont exist
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/file/setup.go')
-rw-r--r-- | plugin/file/setup.go | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/plugin/file/setup.go b/plugin/file/setup.go index 38ba79621..9be09fe8d 100644 --- a/plugin/file/setup.go +++ b/plugin/file/setup.go @@ -57,6 +57,9 @@ func fileParse(c *caddy.Controller) (Zones, error) { config := dnsserver.GetConfig(c) + var openErr error + reload := 1 * time.Minute + for c.Next() { // file db.file [zones...] if !c.NextArg() { @@ -77,22 +80,23 @@ func fileParse(c *caddy.Controller) (Zones, error) { reader, err := os.Open(fileName) if err != nil { - // bail out - return Zones{}, err + openErr = err } for i := range origins { origins[i] = plugin.Host(origins[i]).Normalize() - zone, err := Parse(reader, origins[i], fileName, 0) - if err == nil { - z[origins[i]] = zone - } else { - return Zones{}, err + z[origins[i]] = NewZone(origins[i], fileName) + if openErr == nil { + zone, err := Parse(reader, origins[i], fileName, 0) + if err == nil { + z[origins[i]] = zone + } else { + return Zones{}, err + } } names = append(names, origins[i]) } - reload := 1 * time.Minute upstr := upstream.New() t := []string{} var e error @@ -129,5 +133,13 @@ func fileParse(c *caddy.Controller) (Zones, error) { } } } + if openErr != nil { + if reload == 0 { + // reload hasn't been set make this a fatal error + return Zones{}, plugin.Error("file", openErr) + } + log.Warningf("Failed to open %q: trying again in %s", openErr, reload) + + } return Zones{Z: z, Names: names}, nil } |