diff --git a/nameserver/http.go b/nameserver/http.go index 81e5d040..fee47cb1 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -17,12 +17,13 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, level.Printf("[http] "+logmsg, logargs...) } -func ListenHttp(domain string, db Zone, port int) { +func ListenHttp(version string, server *DNSServer, domain string, db Zone, port int) { muxRouter := mux.NewRouter() muxRouter.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "ok") + io.WriteString(w, fmt.Sprintln("weave DNS", version)) + io.WriteString(w, server.Status()) }) muxRouter.Methods("PUT").Path("/name/{id:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/nameserver/http_test.go b/nameserver/http_test.go index fd613861..6a72b6c6 100644 --- a/nameserver/http_test.go +++ b/nameserver/http_test.go @@ -30,7 +30,7 @@ func TestHttp(t *testing.T) { var zone = new(ZoneDb) port := rand.Intn(10000) + 32768 fmt.Println("Http test on port", port) - go ListenHttp(testDomain, zone, port) + go ListenHttp("", nil, testDomain, zone, port) time.Sleep(100 * time.Millisecond) // Allow for http server to get going diff --git a/nameserver/server.go b/nameserver/server.go index 8b5bb7f7..1c1647b4 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -6,6 +6,7 @@ import ( . "github.com/zettio/weave/common" "net" "sync" + "bytes" ) const ( @@ -142,6 +143,17 @@ func (s *DNSServer) Start() error { return nil } +// Return status string +func (s *DNSServer) Status() string { + var buf bytes.Buffer + buf.WriteString(fmt.Sprintln("Local domain", s.Domain)) + buf.WriteString(fmt.Sprintln("Listen address", s.ListenAddr)) + buf.WriteString(fmt.Sprintln("mDNS interface", s.iface)) + buf.WriteString(fmt.Sprintln("Fallback DNS config", s.upstream)) + buf.WriteString(fmt.Sprintf("Zone database:\n%s", s.zone)) + return buf.String() +} + // Perform a graceful shutdown func (s *DNSServer) Stop() error { if err := s.tcpSrv.Shutdown(); err != nil { diff --git a/nameserver/zone.go b/nameserver/zone.go index ae07eb88..f4c78149 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -5,6 +5,8 @@ import ( . "github.com/zettio/weave/common" "net" "sync" + "bytes" + "fmt" ) const ( @@ -61,6 +63,16 @@ func (zone *ZoneDb) indexOf(match func(Record) bool) int { return -1 } +func (zone *ZoneDb) String() string { + zone.mx.RLock() + defer zone.mx.RUnlock() + var buf bytes.Buffer + for _, r := range zone.recs { + buf.WriteString(fmt.Sprintf("%.12s %s %v\n", r.Ident, r.IP, r.Name)) + } + return buf.String() +} + func (zone *ZoneDb) LookupName(name string) (net.IP, error) { zone.mx.RLock() defer zone.mx.RUnlock() diff --git a/site/troubleshooting.md b/site/troubleshooting.md index ef6f07af..b1cec0e3 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -51,7 +51,7 @@ The command weave status -reports on the current status of the weave router. +reports on the current status of the weave router and DNS. This produces output like: @@ -80,6 +80,8 @@ broadcast: 7a:16:dd:5b:83:de -> [] Reconnects: 192.168.32.1:6783 (next try at 2014-10-23 16:39:50.585932102 +0000 UTC) + +weavedns container is not present; have you launched it? ```` The terms used here are explained further at @@ -117,11 +119,16 @@ weave network is not fully connected. See the [architecture documentation](https://raw.githubusercontent.com/zettio/weave/master/docs/architecture.txt) for a full explanation. -Finally, 'Reconnects' lists peers that this router is aware of, but is +The 'Reconnects' section lists peers that this router is aware of, but is not currently connected to. Each line contains some information about whether it is attempting to connect or is waiting for a while before connecting again. +Finally, status information from weave DNS is included. In this example, +the DNS container has not been launched so no status information is +available (see the [WeaveDNS README](https://github.com/zettio/weave/blob/master/weavedns/README.md) +for more information). + ### List attached containers weave ps diff --git a/weave b/weave index 89763f0f..e73058f1 100755 --- a/weave +++ b/weave @@ -555,7 +555,9 @@ case "$COMMAND" in http_call $CONTAINER_NAME $HTTP_PORT POST /connect -d "peer=$1" ;; status) - http_call $CONTAINER_NAME $HTTP_PORT GET /status + http_call $CONTAINER_NAME $HTTP_PORT GET /status || true + echo + http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status || true ;; ps) [ $# -eq 0 ] || usage diff --git a/weavedns/README.md b/weavedns/README.md index e27f3b23..90b2bd86 100644 --- a/weavedns/README.md +++ b/weavedns/README.md @@ -177,6 +177,41 @@ $ dns_ip=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weavedns) $ curl -X DELETE "http://$dns_ip:6785/name/$shell2/10.2.1.27" ``` +## Troubleshooting + +The command + + weave status + +reports on the current status of the weave router and DNS: + +```` +weave router git-8f675f15c0b5 +... + +weave DNS git-8f675f15c0b5 +Local domain weave.local. +Listen address :53 +mDNS interface &{26 65535 ethwe fa:b6:b1:85:ac:9b up|broadcast|multicast} +Fallback DNS config &{[66.28.0.45 8.8.8.8] [] 53 1 5 2} +Zone database: +710978857a88 10.2.1.26 wiff.weave.local. +e8d85b1dcdb1 10.2.1.27 waff.weave.local. +26bd05f9a0cb 10.2.1.28 ping.weave.local. +1ab0e8b17c39 10.2.1.29 pong.weave.local. +```` + +The first section covers the router; see the troubleshooting guide in +the main documentation for more detail. + +The second section is pertinent to weaveDNS, and includes: + +* The local domain suffix which is being served +* The address on which the DNS server is listening +* The interface being used for multicast DNS +* The fallback DNS which will be used to resolve non local names +* The names known to the local weaveDNS server. Each entry comprises the container ID, IP address and its fully qualified domain name + ## Present limitations * The server will not know about restarted containers, but if you diff --git a/weavedns/main.go b/weavedns/main.go index 46560467..53ddd987 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -83,11 +83,11 @@ func main() { Debug.Printf("DNS fallback at %s:%s", fallbackHost, fallbackPort) } - go weavedns.ListenHttp(localDomain, zone, httpPort) srv, err := weavedns.NewDNSServer(srvConfig, zone, iface) if err != nil { Error.Fatal("Failed to initialize the WeaveDNS server", err) } + go weavedns.ListenHttp(version, srv, localDomain, zone, httpPort) err = srv.Start() if err != nil { Error.Fatal("Failed to start the WeaveDNS server", err)