diff --git a/caddy/restart.go b/caddy/restart.go index 6237c960..28b79d7a 100644 --- a/caddy/restart.go +++ b/caddy/restart.go @@ -172,32 +172,3 @@ func getCertsForNewCaddyfile(newCaddyfile Input) error { return nil } - -// restartInProc restarts Caddy forcefully in process using newCaddyfile. -func restartInProc(newCaddyfile Input) error { - wg.Add(1) // barrier so Wait() doesn't unblock - - err := Stop() - if err != nil { - 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 - } - - wg.Done() // take down our barrier - - return nil -} diff --git a/caddy/restart_windows.go b/caddy/restart_windows.go index b54f38a3..d860e913 100644 --- a/caddy/restart_windows.go +++ b/caddy/restart_windows.go @@ -7,32 +7,11 @@ import "log" func Restart(newCaddyfile Input) error { log.Println("[INFO] Restarting") - caddyfileMu.Lock() - oldCaddyfile := caddyfile if newCaddyfile == nil { + caddyfileMu.Lock() newCaddyfile = caddyfile - } - caddyfileMu.Unlock() - - wg.Add(1) // barrier so Wait() doesn't unblock - - err := Stop() - if err != nil { - return err + 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 - } - - wg.Done() // take down our barrier - - return nil + return restartInProc(newCaddyfile) } diff --git a/caddy/restartinproc.go b/caddy/restartinproc.go new file mode 100644 index 00000000..045e4ccc --- /dev/null +++ b/caddy/restartinproc.go @@ -0,0 +1,32 @@ +package caddy + +import "log" + +// restartInProc restarts Caddy forcefully in process using newCaddyfile. +func restartInProc(newCaddyfile Input) error { + wg.Add(1) // barrier so Wait() doesn't unblock + + err := Stop() + if err != nil { + 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 + } + + wg.Done() // take down our barrier + + return nil +}