Check with Docker whether the container is really running

This commit is contained in:
Alvaro Saurin committed 2015-06-10 22:27:49 +02:00
1 parent 1889a4a87f
commit 698d352322
3 files changed
+18 -3

No files matched your search

+16 -1
View File
@@ -9,6 +9,7 @@ import (
"github.com/gorilla/mux"
"github.com/miekg/dns"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
)
func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string,
@@ -24,7 +25,7 @@ func extractFQDN(r *http.Request) (string, string) {
return "*", ""
}
func ServeHTTP(listener net.Listener, version string, server *DNSServer) {
func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerCli *docker.Client) {
muxRouter := mux.NewRouter()
@@ -66,6 +67,20 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer) {
return
} // oh, I already know this. whatever.
}
if dockerCli != nil {
if !docker.IsContainerID(idStr) {
Debug.Printf("[http] '%s' does not seem a container id", idStr)
return
}
if running, err := dockerCli.IsContainerRunning(idStr); err != nil {
Error.Printf("[http] Could not check container status: %s", err)
} else if !running {
Info.Printf("[http] '%s' is not running: removing", idStr)
server.Zone.DeleteRecords(idStr, name, ip)
}
}
} else {
Info.Printf("[http] Ignoring name %s, not in %s", name, domain)
}
+1 -1
View File
@@ -42,7 +42,7 @@ func TestHttp(t *testing.T) {
srv, _ := NewDNSServer(DNSServerConfig{Zone: zone})
port := httpListener.Addr().(*net.TCPAddr).Port
go ServeHTTP(httpListener, "", srv)
go ServeHTTP(httpListener, "", srv, nil)
// Ask the http server to add our test address into the database
addrParts := strings.Split(testAddr1, "/")
+1 -1
View File
@@ -145,7 +145,7 @@ func main() {
}
go SignalHandlerLoop(srv)
go weavedns.ServeHTTP(httpListener, version, srv)
go weavedns.ServeHTTP(httpListener, version, srv, dockerCli)
err = srv.Start()
if err != nil {