Files
weave/server/updater.go
T
Michael Bridgen 0749460652 Moved updater into server
While we're only reacting to containers going away, it's more
convenient to bundle the docker events watcher into the server.

I've added a flag to switch it on; and switched it on by default in
the container.

I also implemented `Zone.DeleteRecordsFor(ident)`, which removes all
records for a particular container.

One minor change to the structure of the code is that the Zone is now
constructed *outside* the server, and given to it and the updater.
2014-10-16 15:38:32 +01:00

35 lines
669 B
Go

package weavedns
import (
"github.com/fsouza/go-dockerclient"
"log"
)
func StartUpdater(apiPath string, zone Zone) error {
client, err := docker.NewClient(apiPath)
if err != nil {
log.Fatalf("Unable to connect to Docker API on %s: %s", apiPath, err)
}
events := make(chan *docker.APIEvents)
client.AddEventListener(events)
log.Printf("Using Docker API on %s", apiPath)
go func() {
for event := range events {
handleEvent(zone, event, client)
}
}()
return nil
}
func handleEvent(zone Zone, event *docker.APIEvents, client *docker.Client) error {
switch event.Status {
case "die":
id := event.ID
zone.DeleteRecordsFor(id)
}
return nil
}