2016-03-18 20:57:35 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
2016-04-28 11:07:44 -07:00
|
|
|
// Restart restarts CoreDNS forcefully using newCorefile,
|
|
|
|
|
// or, if nil, the current/existing Corefile is reused.
|
|
|
|
|
func Restart(newCorefile Input) error {
|
2016-03-18 20:57:35 +00:00
|
|
|
log.Println("[INFO] Restarting")
|
|
|
|
|
|
2016-04-28 11:07:44 -07:00
|
|
|
if newCorefile == nil {
|
|
|
|
|
corefileMu.Lock()
|
|
|
|
|
newCorefile = corefile
|
|
|
|
|
corefileMu.Unlock()
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wg.Add(1) // barrier so Wait() doesn't unblock
|
|
|
|
|
|
|
|
|
|
err := Stop()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 11:07:44 -07:00
|
|
|
err = Start(newCorefile)
|
2016-03-18 20:57:35 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wg.Done() // take down our barrier
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|