Don't forget to Shutdown the DNS Server!
Fixes #609 Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
This commit is contained in:
parent
17cf8cc4f8
commit
f026b8781e
|
@ -571,6 +571,9 @@ func (c *Command) Run(args []string) int {
|
|||
if c.rpcServer != nil {
|
||||
defer c.rpcServer.Shutdown()
|
||||
}
|
||||
if c.dnsServer != nil {
|
||||
defer c.dnsServer.Shutdown()
|
||||
}
|
||||
|
||||
for _, server := range c.httpServers {
|
||||
defer server.Shutdown()
|
||||
|
|
|
@ -33,6 +33,16 @@ type DNSServer struct {
|
|||
logger *log.Logger
|
||||
}
|
||||
|
||||
// Shutdown stops the DNS Servers
|
||||
func (d *DNSServer) Shutdown() {
|
||||
if err := d.dnsServer.Shutdown(); err != nil {
|
||||
d.logger.Printf("[ERR] dns: error stopping udp server: %v", err)
|
||||
}
|
||||
if err := d.dnsServerTCP.Shutdown(); err != nil {
|
||||
d.logger.Printf("[ERR] dns: error stopping tcp server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// NewDNSServer starts a new DNS server to provide an agent interface
|
||||
func NewDNSServer(agent *Agent, config *DNSConfig, logOutput io.Writer, domain string, bind string, recursors []string) (*DNSServer, error) {
|
||||
// Make sure domain is FQDN
|
||||
|
@ -92,16 +102,18 @@ func NewDNSServer(agent *Agent, config *DNSConfig, logOutput io.Writer, domain s
|
|||
// Async start the DNS Servers, handle a potential error
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
err := server.ListenAndServe()
|
||||
srv.logger.Printf("[ERR] dns: error starting udp server: %v", err)
|
||||
errCh <- fmt.Errorf("dns udp setup failed: %v", err)
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
srv.logger.Printf("[ERR] dns: error starting udp server: %v", err)
|
||||
errCh <- fmt.Errorf("dns udp setup failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
errChTCP := make(chan error, 1)
|
||||
go func() {
|
||||
err := serverTCP.ListenAndServe()
|
||||
srv.logger.Printf("[ERR] dns: error starting tcp server: %v", err)
|
||||
errChTCP <- fmt.Errorf("dns tcp setup failed: %v", err)
|
||||
if err := serverTCP.ListenAndServe(); err != nil {
|
||||
srv.logger.Printf("[ERR] dns: error starting tcp server: %v", err)
|
||||
errChTCP <- fmt.Errorf("dns tcp setup failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Check the server is running, do a test lookup
|
||||
|
|
Loading…
Reference in New Issue