diff --git a/caddy/caddy.go b/caddy/caddy.go index b80450ee0..9383e3860 100644 --- a/caddy/caddy.go +++ b/caddy/caddy.go @@ -319,4 +319,8 @@ type Input interface { // Gets the path to the origin file Path() string + + // IsFile returns true if the original input was a file on the file system + // that could be loaded again later if requested. + IsFile() bool } diff --git a/caddy/helpers.go b/caddy/helpers.go index c30d7c168..d8f409708 100644 --- a/caddy/helpers.go +++ b/caddy/helpers.go @@ -58,6 +58,7 @@ func isRestart() bool { type CaddyfileInput struct { Filepath string Contents []byte + RealFile bool } // Body returns c.Contents. @@ -65,3 +66,6 @@ func (c CaddyfileInput) Body() []byte { return c.Contents } // Path returns c.Filepath. func (c CaddyfileInput) Path() string { return c.Filepath } + +// Path returns true if the original input was a real file on the file system. +func (c CaddyfileInput) IsFile() bool { return c.RealFile } diff --git a/caddy/sigtrap_posix.go b/caddy/sigtrap_posix.go index 789985efb..122adf2c3 100644 --- a/caddy/sigtrap_posix.go +++ b/caddy/sigtrap_posix.go @@ -3,6 +3,7 @@ package caddy import ( + "io/ioutil" "log" "os" "os/signal" @@ -17,7 +18,23 @@ func init() { for { <-reload - err := Restart(nil) + + var updatedCaddyfile Input + + caddyfileMu.Lock() + if caddyfile.IsFile() { + body, err := ioutil.ReadFile(caddyfile.Path()) + if err == nil { + caddyfile = CaddyfileInput{ + Filepath: caddyfile.Path(), + Contents: body, + RealFile: true, + } + } + } + caddyfileMu.Unlock() + + err := Restart(updatedCaddyfile) if err != nil { log.Println(err) } diff --git a/main.go b/main.go index 8e4bffc2c..15d39de55 100644 --- a/main.go +++ b/main.go @@ -92,6 +92,7 @@ func loadCaddyfile() (caddy.Input, error) { return caddy.CaddyfileInput{ Contents: contents, Filepath: conf, + RealFile: true, }, nil } @@ -115,6 +116,7 @@ func loadCaddyfile() (caddy.Input, error) { return caddy.CaddyfileInput{ Contents: contents, Filepath: caddy.DefaultConfigFile, + RealFile: true, }, nil }