Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
367d2857
Commit
367d2857
authored
Jul 30, 2019
by
Erik Wilson
Committed by
corbot[bot]
Jul 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/reload: Graceful reload of imported files (#3068)
Automatically submitted.
parent
4fda9535
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
plugin/reload/README.md
plugin/reload/README.md
+3
-2
plugin/reload/reload.go
plugin/reload/reload.go
+23
-2
No files found.
plugin/reload/README.md
View file @
367d2857
...
...
@@ -89,8 +89,9 @@ closed in step 1; so the health endpoint is broken. The same can hopen in the pr
In general be careful with assigning new port and expecting reload to work fully.
Also any
`import`
statement is not discovered by this plugin. This means if any of these imported files
changes the
*reload*
plugin is ignorant of that fact.
In CoreDNS v1.6.0 and earlier any
`import`
statements are not discovered by this plugin.
This means if any of these imported files changes the
*reload*
plugin is ignorant of that fact.
CoreDNS v1.7.0 and later does parse the Corefile and supports detecting changes in imported files.
## Metrics
...
...
plugin/reload/reload.go
View file @
367d2857
package
reload
import
(
"bytes"
"crypto/md5"
"encoding/json"
"sync"
"time"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy/caddyfile"
)
// reload periodically checks if the Corefile has changed, and reloads if so
...
...
@@ -46,6 +49,14 @@ func (r *reload) interval() time.Duration {
return
r
.
dur
}
func
parse
(
corefile
caddy
.
Input
)
([]
byte
,
error
)
{
serverBlocks
,
err
:=
caddyfile
.
Parse
(
corefile
.
Path
(),
bytes
.
NewReader
(
corefile
.
Body
()),
nil
)
if
err
!=
nil
{
return
nil
,
err
}
return
json
.
Marshal
(
serverBlocks
)
}
func
hook
(
event
caddy
.
EventName
,
info
interface
{})
error
{
if
event
!=
caddy
.
InstanceStartupEvent
{
return
nil
...
...
@@ -60,7 +71,12 @@ func hook(event caddy.EventName, info interface{}) error {
// this should be an instance. ok to panic if not
instance
:=
info
.
(
*
caddy
.
Instance
)
md5sum
:=
md5
.
Sum
(
instance
.
Caddyfile
()
.
Body
())
parsedCorefile
,
err
:=
parse
(
instance
.
Caddyfile
())
if
err
!=
nil
{
return
err
}
md5sum
:=
md5
.
Sum
(
parsedCorefile
)
log
.
Infof
(
"Running configuration MD5 = %x
\n
"
,
md5sum
)
go
func
()
{
...
...
@@ -73,7 +89,12 @@ func hook(event caddy.EventName, info interface{}) error {
if
err
!=
nil
{
continue
}
s
:=
md5
.
Sum
(
corefile
.
Body
())
parsedCorefile
,
err
:=
parse
(
corefile
)
if
err
!=
nil
{
log
.
Warningf
(
"Corefile parse failed: %s"
,
err
)
continue
}
s
:=
md5
.
Sum
(
parsedCorefile
)
if
s
!=
md5sum
{
// Let not try to restart with the same file, even though it is wrong.
md5sum
=
s
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment