mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-27 23:03:37 -05:00
Extract restartInProc to its own file
This commit is contained in:
parent
86ccafbe58
commit
32e63e6b94
3 changed files with 35 additions and 53 deletions
|
@ -172,32 +172,3 @@ func getCertsForNewCaddyfile(newCaddyfile Input) error {
|
||||||
|
|
||||||
return nil
|
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 {
|
func Restart(newCaddyfile Input) error {
|
||||||
log.Println("[INFO] Restarting")
|
log.Println("[INFO] Restarting")
|
||||||
|
|
||||||
caddyfileMu.Lock()
|
|
||||||
oldCaddyfile := caddyfile
|
|
||||||
if newCaddyfile == nil {
|
if newCaddyfile == nil {
|
||||||
|
caddyfileMu.Lock()
|
||||||
newCaddyfile = caddyfile
|
newCaddyfile = caddyfile
|
||||||
}
|
|
||||||
caddyfileMu.Unlock()
|
caddyfileMu.Unlock()
|
||||||
|
|
||||||
wg.Add(1) // barrier so Wait() doesn't unblock
|
|
||||||
|
|
||||||
err := Stop()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = Start(newCaddyfile)
|
return restartInProc(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
|
|
||||||
}
|
}
|
||||||
|
|
32
caddy/restartinproc.go
Normal file
32
caddy/restartinproc.go
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue