mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	
		
			
	
	
		
			32 lines
		
	
	
		
			529 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			529 B
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package core
 | ||
|  | 
 | ||
|  | import "log"
 | ||
|  | 
 | ||
|  | // Restart restarts Caddy forcefully using newCaddyfile,
 | ||
|  | // or, if nil, the current/existing Caddyfile is reused.
 | ||
|  | func Restart(newCaddyfile Input) error {
 | ||
|  | 	log.Println("[INFO] Restarting")
 | ||
|  | 
 | ||
|  | 	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 {
 | ||
|  | 		return err
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	wg.Done() // take down our barrier
 | ||
|  | 
 | ||
|  | 	return nil
 | ||
|  | }
 |