Commit 32e63e6b authored by Benny Ng's avatar Benny Ng

Extract restartInProc to its own file

parent 86ccafbe
......@@ -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
}
......@@ -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
}
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)
}
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
}
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