Attach existing weave containers at startup

This commit is contained in:
Bryan Boreham committed 2015-09-01 17:48:22 +01:00
1 parent 81e8ba223f
commit 9ae6435317
2 files changed
+16 -2

No files matched your search

+3 -1
View File
@@ -59,6 +59,8 @@ func main() {
Log.Fatalf("Could not start proxy: %s", err)
}
go p.ListenAndServe()
listeners := p.Listen()
p.AttachExistingContainers()
go p.Serve(listeners)
SignalHandlerLoop()
}
+13 -1
View File
@@ -93,6 +93,15 @@ func NewProxy(c Config) (*Proxy, error) {
return p, nil
}
func (proxy *Proxy) AttachExistingContainers() {
containers, _ := proxy.client.ListContainers(docker.ListContainersOptions{})
for _, cont := range containers {
if strings.HasPrefix(cont.Command, weaveWaitEntrypoint[0]) {
proxy.ContainerStarted(cont.ID)
}
}
}
func (proxy *Proxy) Dial() (net.Conn, error) {
return net.Dial("unix", dockerSock)
}
@@ -131,7 +140,7 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
proxy.Intercept(i, w, r)
}
func (proxy *Proxy) ListenAndServe() {
func (proxy *Proxy) Listen() []net.Listener {
listeners := []net.Listener{}
addrs := []string{}
for _, addr := range proxy.ListenAddrs {
@@ -146,7 +155,10 @@ func (proxy *Proxy) ListenAndServe() {
for _, addr := range addrs {
Log.Infoln("proxy listening on", addr)
}
return listeners
}
func (proxy *Proxy) Serve(listeners []net.Listener) {
errs := make(chan error)
for _, listener := range listeners {
go func(listener net.Listener) {