Skip to content

Commit

Permalink
Wait for plugin status via unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Jan 29, 2016
1 parent a03802c commit f34b0f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 18 additions & 0 deletions prog/plugin/main.go
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -90,6 +91,7 @@ func main() {
createNetwork(dockerClient, meshNetworkName, meshAddress)
}

go listenAndServeStatus("/home/weave/status.sock")
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM)

Expand Down Expand Up @@ -161,3 +163,19 @@ func createNetwork(dockerClient *docker.Client, networkName, address string) {
}
}
}

func listenAndServeStatus(socket string) {
if err := os.Remove(socket); err != nil && !os.IsNotExist(err) {
Log.Fatalf("Error removing existing status socket: %s", err)
}
listener, err := net.Listen("unix", socket)
if err != nil {
Log.Fatalf("ListenAndServeStatus failed: %s", err)
}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "ok")
})
if err := (&http.Server{Handler: handler}).Serve(listener); err != nil {
Log.Fatalf("ListenAndServeStatus failed: %s", err)
}
}
3 changes: 1 addition & 2 deletions weave
Expand Up @@ -1698,6 +1698,7 @@ launch_plugin_if_not_running() {
$(docker_sock_options) \
-v /run/docker/plugins:/run/docker/plugins \
$PLUGIN_IMAGE "$@")
wait_for_status $PLUGIN_CONTAINER_NAME http_call_unix $PLUGIN_CONTAINER_NAME status.sock
}

plugin_disabled() {
Expand Down Expand Up @@ -1880,8 +1881,6 @@ EOF
;;
launch-plugin)
launch_plugin_if_not_running "$@"
fractional_sleep 0.1
check_running $PLUGIN_CONTAINER_NAME 2>/dev/null || (death_msg $PLUGIN_CONTAINER_NAME ; exit 1)
echo $PLUGIN_CONTAINER
;;
env|proxy-env)
Expand Down

0 comments on commit f34b0f7

Please sign in to comment.