aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/coredns.go3
-rw-r--r--core/dnsserver/register.go24
-rw-r--r--core/dnsserver/server.go13
-rw-r--r--coremain/run.go47
4 files changed, 44 insertions, 43 deletions
diff --git a/core/coredns.go b/core/coredns.go
index 369230492..eb6e204d6 100644
--- a/core/coredns.go
+++ b/core/coredns.go
@@ -23,6 +23,3 @@ import (
_ "github.com/miekg/coredns/middleware/secondary"
_ "github.com/miekg/coredns/middleware/whoami"
)
-
-// Quiet mode will not show any informative output on initialization.
-var Quiet bool
diff --git a/core/dnsserver/register.go b/core/dnsserver/register.go
index c470c9c6d..047fb673f 100644
--- a/core/dnsserver/register.go
+++ b/core/dnsserver/register.go
@@ -1,6 +1,7 @@
package dnsserver
import (
+ "flag"
"fmt"
"net"
"time"
@@ -12,19 +13,15 @@ import (
const serverType = "dns"
func init() {
+ flag.StringVar(&Port, "port", DefaultPort, "Default port")
+ flag.BoolVar(&Quiet, "quiet", false, "Quiet mode (no initialization output)")
+
caddy.RegisterServerType(serverType, caddy.ServerType{
Directives: func() []string { return directives },
DefaultInput: func() caddy.Input {
- if Port == DefaultPort && Zone != "" {
- return caddy.CaddyfileInput{
- Filepath: "Corefile",
- Contents: nil,
- ServerTypeName: serverType,
- }
- }
return caddy.CaddyfileInput{
Filepath: "Corefile",
- Contents: nil,
+ Contents: []byte(".:" + Port + " {\nwhoami\n}\n"),
ServerTypeName: serverType,
}
},
@@ -63,7 +60,6 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
s.Keys[i] = za.String()
if v, ok := dups[za.Zone]; ok {
return nil, fmt.Errorf("cannot serve %s - zone already defined for %v", za, v)
-
}
dups[za.Zone] = za.String()
@@ -71,7 +67,6 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
cfg := &Config{
Zone: za.Zone,
Port: za.Port,
- // TODO(miek): more?
}
h.saveConfig(za.String(), cfg)
}
@@ -129,8 +124,6 @@ func groupConfigsByListenAddr(configs []*Config) (map[string][]*Config, error) {
}
const (
- // DefaultZone is the default zone.
- DefaultZone = "."
// DefaultPort is the default port.
DefaultPort = "2053"
// DefaultRoot is the default root folder.
@@ -141,14 +134,15 @@ const (
// command line flags, etc.
var (
// Root is the site root
+ // TODO(miek): double check if this is used and if we want to use it.
Root = DefaultRoot
- // Host is the site host
- Zone = DefaultZone
-
// Port is the site port
Port = DefaultPort
// GracefulTimeout is the maximum duration of a graceful shutdown.
GracefulTimeout time.Duration
+
+ // Quiet mode will not show any informative output on initialization.
+ Quiet bool
)
diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go
index 77a28f477..4e02f1c21 100644
--- a/core/dnsserver/server.go
+++ b/core/dnsserver/server.go
@@ -1,6 +1,7 @@
package dnsserver
import (
+ "fmt"
"log"
"net"
"runtime"
@@ -213,6 +214,18 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
log.Printf("[INFO] \"%s %s %s\" - No such zone at %s (Remote: %s)", dns.Type(r.Question[0].Qtype), dns.Class(r.Question[0].Qclass), q, s.Addr, remoteHost)
}
+// OnStartupComplete lists the sites served by this server
+// and any relevant information, assuming Quiet == false.
+func (s *Server) OnStartupComplete() {
+ if Quiet {
+ return
+ }
+
+ for zone, config := range s.zones {
+ fmt.Println(zone + ":" + config.Port)
+ }
+}
+
// DefaultErrorFunc responds to an DNS request with an error.
func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int) {
state := request.Request{W: w, Req: r}
diff --git a/coremain/run.go b/coremain/run.go
index 94b0076a0..7552074c1 100644
--- a/coremain/run.go
+++ b/coremain/run.go
@@ -13,8 +13,9 @@ import (
"github.com/mholt/caddy"
+ "github.com/miekg/coredns/core/dnsserver"
// Plug in CoreDNS
- "github.com/miekg/coredns/core"
+ _ "github.com/miekg/coredns/core"
)
func init() {
@@ -28,7 +29,6 @@ func init() {
flag.BoolVar(&plugins, "plugins", false, "List installed plugins")
flag.StringVar(&logfile, "log", "", "Process log file")
flag.StringVar(&caddy.PidFile, "pidfile", "", "Path to write pid file")
- flag.BoolVar(&core.Quiet, "quiet", false, "Quiet mode (no initialization output)")
flag.BoolVar(&version, "version", false, "Show version")
caddy.RegisterCaddyfileLoader("flag", caddy.LoaderFunc(confLoader))
@@ -80,34 +80,12 @@ func Run() {
}
logVersion()
+ showVersion()
// Twiddle your thumbs
instance.Wait()
}
-// startNotification will log CoreDNS' version to the log.
-func startupNotification() {
- if core.Quiet {
- return
- }
- logVersion()
-}
-
-func showVersion() {
- fmt.Printf("%s-%s\n", caddy.AppName, caddy.AppVersion)
- if devBuild && gitShortStat != "" {
- fmt.Printf("%s\n%s\n", gitShortStat, gitFilesModified)
- }
-}
-
-// logVersion logs the version that is starting.
-func logVersion() {
- log.Printf("[INFO] %s-%s starting\n", caddy.AppName, caddy.AppVersion)
- if devBuild && gitShortStat != "" {
- log.Printf("[INFO] %s\n%s\n", gitShortStat, gitFilesModified)
- }
-}
-
// mustLogFatal wraps log.Fatal() in a way that ensures the
// output is always printed to stderr so the user can see it
// if the user is still there, even if the process log was not
@@ -158,6 +136,25 @@ func defaultLoader(serverType string) (caddy.Input, error) {
}, nil
}
+// logVersion logs the version that is starting.
+func logVersion() { log.Print("[INFO] " + versionString()) }
+
+// showVersion prints the version that is starting.
+func showVersion() {
+ if dnsserver.Quiet {
+ return
+ }
+ fmt.Print(versionString())
+ if devBuild && gitShortStat != "" {
+ fmt.Printf("%s\n%s\n", gitShortStat, gitFilesModified)
+ }
+}
+
+// versionString returns the CoreDNS version as a string.
+func versionString() string {
+ return fmt.Sprintf("%s-%s starting\n", caddy.AppName, caddy.AppVersion)
+}
+
// setVersion figures out the version information
// based on variables set by -ldflags.
func setVersion() {