mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-09 20:38:49 +03:00
core: Fix for graceful reload after first reload signal
The file path of the originally-loaded Caddyfile must be piped to the forked process; previously it was using stdin after the first fork, which wouldn't load the newest Caddyfile from disk, which is the point of SIGUSR1.
This commit is contained in:
parent
89ad7593bd
commit
e3be524447
4 changed files with 14 additions and 8 deletions
|
@ -264,10 +264,7 @@ func LoadCaddyfile(loader func() (Input, error)) (cdyfile Input, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cdyfile = CaddyfileInput{
|
cdyfile = loadedGob.Caddyfile
|
||||||
Filepath: os.Stdin.Name(),
|
|
||||||
Contents: loadedGob.Caddyfile,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we first try to get from stdin pipe
|
// Otherwise, we first try to get from stdin pipe
|
||||||
|
|
|
@ -43,7 +43,7 @@ func checkFdlimit() {
|
||||||
// the caddyfile contents. Used only during graceful restarts.
|
// the caddyfile contents. Used only during graceful restarts.
|
||||||
type caddyfileGob struct {
|
type caddyfileGob struct {
|
||||||
ListenerFds map[string]uintptr
|
ListenerFds map[string]uintptr
|
||||||
Caddyfile []byte
|
Caddyfile Input
|
||||||
}
|
}
|
||||||
|
|
||||||
// isRestart returns whether this process is, according
|
// isRestart returns whether this process is, according
|
||||||
|
|
|
@ -10,6 +10,10 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gob.Register(CaddyfileInput{})
|
||||||
|
}
|
||||||
|
|
||||||
// Restart restarts the entire application; gracefully with zero
|
// Restart restarts the entire application; gracefully with zero
|
||||||
// downtime if on a POSIX-compatible system, or forcefully if on
|
// downtime if on a POSIX-compatible system, or forcefully if on
|
||||||
// Windows but with imperceptibly-short downtime.
|
// Windows but with imperceptibly-short downtime.
|
||||||
|
@ -17,6 +21,11 @@ import (
|
||||||
// The restarted application will use newCaddyfile as its input
|
// The restarted application will use newCaddyfile as its input
|
||||||
// configuration. If newCaddyfile is nil, the current (existing)
|
// configuration. If newCaddyfile is nil, the current (existing)
|
||||||
// Caddyfile configuration will be used.
|
// Caddyfile configuration will be used.
|
||||||
|
//
|
||||||
|
// Note: The process must exist in the same place on the disk in
|
||||||
|
// order for this to work. Thus, multiple graceful restarts don't
|
||||||
|
// work if executing with `go run`, since the binary is cleaned up
|
||||||
|
// when `go run` sees the initial parent process exit.
|
||||||
func Restart(newCaddyfile Input) error {
|
func Restart(newCaddyfile Input) error {
|
||||||
if newCaddyfile == nil {
|
if newCaddyfile == nil {
|
||||||
caddyfileMu.Lock()
|
caddyfileMu.Lock()
|
||||||
|
@ -24,7 +33,7 @@ func Restart(newCaddyfile Input) error {
|
||||||
caddyfileMu.Unlock()
|
caddyfileMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) == 0 { // this should never happen, but just in case...
|
if len(os.Args) == 0 { // this should never happen...
|
||||||
os.Args = []string{""}
|
os.Args = []string{""}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +43,7 @@ func Restart(newCaddyfile Input) error {
|
||||||
// Prepare our payload to the child process
|
// Prepare our payload to the child process
|
||||||
cdyfileGob := caddyfileGob{
|
cdyfileGob := caddyfileGob{
|
||||||
ListenerFds: make(map[string]uintptr),
|
ListenerFds: make(map[string]uintptr),
|
||||||
Caddyfile: newCaddyfile.Body(),
|
Caddyfile: newCaddyfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a pipe to the fork's stdin so it can get the Caddyfile
|
// Prepare a pipe to the fork's stdin so it can get the Caddyfile
|
||||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
||||||
|
|
||||||
err := Restart(updatedCaddyfile)
|
err := Restart(updatedCaddyfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println("error at restart:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue