mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 10:25:46 +03:00
32 lines
671 B
Go
32 lines
671 B
Go
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
|
|
}
|