func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddress string, noMulticastRoute bool) error { endChan := make(chan error, 1) if address != "" { globalListener, err := listenAndServe(dockerClient, weave, address, noMulticastRoute, endChan, "global", false) if err != nil { return err } defer os.Remove(address) defer globalListener.Close() } if meshAddress != "" { meshListener, err := listenAndServe(dockerClient, weave, meshAddress, noMulticastRoute, endChan, "local", true) if err != nil { return err } defer os.Remove(meshAddress) defer meshListener.Close() } statusListener, err := weavenet.ListenUnixSocket("/home/weave/status.sock") if err != nil { return err } go serveStatus(statusListener) sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM) select { case sig := <-sigChan: Log.Debugf("Caught signal %s; shutting down", sig) return nil case err := <-endChan: return err } }
func (proxy *Proxy) ListenAndServeStatus(socket string) { listener, err := weavenet.ListenUnixSocket(socket) if err != nil { Log.Fatalf("ListenAndServeStatus failed: %s", err) } handler := http.HandlerFunc(proxy.StatusHTTP) if err := (&http.Server{Handler: handler}).Serve(listener); err != nil { Log.Fatalf("ListenAndServeStatus failed: %s", err) } }
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, noMulticastRoute bool, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) { d, err := netplugin.New(dockerClient, weave, scope, noMulticastRoute) if err != nil { return nil, err } var i ipamapi.Ipam if withIpam { i = ipamplugin.NewIpam(weave) } listener, err := weavenet.ListenUnixSocket(address) if err != nil { return nil, err } Log.Printf("Listening on %s for %s scope", address, scope) go func() { endChan <- skel.Listen(listener, d, i) }() return listener, nil }
func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address string, endChan chan<- error, scope string, withIpam bool) (net.Listener, error) { name := strings.TrimSuffix(path.Base(address), ".sock") d, err := netplugin.New(dockerClient, weave, name, scope) if err != nil { return nil, err } var i ipamapi.Ipam if withIpam { i = ipamplugin.NewIpam(weave) } listener, err := weavenet.ListenUnixSocket(address) if err != nil { return nil, err } Log.Printf("Listening on %s for %s scope", address, scope) go func() { endChan <- skel.Listen(listener, d, i) }() return listener, nil }