Commit b952fd8f authored by Benny Ng's avatar Benny Ng

revert to old Caddyfile on failed in-process restart

parent 28e0bfbb
...@@ -182,8 +182,18 @@ func restartInProc(newCaddyfile Input) error { ...@@ -182,8 +182,18 @@ func restartInProc(newCaddyfile Input) error {
return err return err
} }
caddyfileMu.Lock()
oldCaddyfile := caddyfile
caddyfileMu.Unlock()
err = Start(newCaddyfile) err = Start(newCaddyfile)
if err != nil { 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 return err
} }
......
...@@ -7,11 +7,12 @@ import "log" ...@@ -7,11 +7,12 @@ import "log"
func Restart(newCaddyfile Input) error { func Restart(newCaddyfile Input) error {
log.Println("[INFO] Restarting") log.Println("[INFO] Restarting")
if newCaddyfile == nil {
caddyfileMu.Lock() caddyfileMu.Lock()
oldCaddyfile := caddyfile
if newCaddyfile == nil {
newCaddyfile = caddyfile newCaddyfile = caddyfile
caddyfileMu.Unlock()
} }
caddyfileMu.Unlock()
wg.Add(1) // barrier so Wait() doesn't unblock wg.Add(1) // barrier so Wait() doesn't unblock
...@@ -22,6 +23,12 @@ func Restart(newCaddyfile Input) error { ...@@ -22,6 +23,12 @@ func Restart(newCaddyfile Input) error {
err = Start(newCaddyfile) err = Start(newCaddyfile)
if err != nil { 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 return err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment