mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
Merge pull request #725 from tpng/reload-validate-caddyfile
revert to old Caddyfile on failed in-process restart
This commit is contained in:
commit
31062dd6c2
|
@ -182,8 +182,18 @@ func restartInProc(newCaddyfile Input) error {
|
|||
return err
|
||||
}
|
||||
|
||||
caddyfileMu.Lock()
|
||||
oldCaddyfile := caddyfile
|
||||
caddyfileMu.Unlock()
|
||||
|
||||
err = Start(newCaddyfile)
|
||||
if err != nil {
|
||||
// revert to old Caddyfile
|
||||
if oldErr := Start(oldCaddyfile); oldErr != nil {
|
||||
log.Printf("[ERROR] Restart: in-process restart failed and cannot revert to old Caddyfile: %v", oldErr)
|
||||
} else {
|
||||
wg.Done() // take down our barrier
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@ import "log"
|
|||
func Restart(newCaddyfile Input) error {
|
||||
log.Println("[INFO] Restarting")
|
||||
|
||||
caddyfileMu.Lock()
|
||||
oldCaddyfile := caddyfile
|
||||
if newCaddyfile == nil {
|
||||
caddyfileMu.Lock()
|
||||
newCaddyfile = caddyfile
|
||||
caddyfileMu.Unlock()
|
||||
}
|
||||
caddyfileMu.Unlock()
|
||||
|
||||
wg.Add(1) // barrier so Wait() doesn't unblock
|
||||
|
||||
|
@ -22,6 +23,12 @@ func Restart(newCaddyfile Input) error {
|
|||
|
||||
err = Start(newCaddyfile)
|
||||
if err != nil {
|
||||
// revert to old Caddyfile
|
||||
if oldErr := Start(oldCaddyfile); oldErr != nil {
|
||||
log.Printf("[ERROR] Restart: in-process restart failed and cannot revert to old Caddyfile: %v", oldErr)
|
||||
} else {
|
||||
wg.Done() // take down our barrier
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user