Skip to content

Commit

Permalink
Warn user if weave network is in use on stop or reset
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Dec 17, 2015
1 parent 357f672 commit ecf4a82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 15 additions & 4 deletions prog/plugin/main.go
Expand Up @@ -29,6 +29,7 @@ func main() {
logLevel string
meshNetworkName string
noMulticastRoute bool
removeNetwork bool
)

flag.BoolVar(&justVersion, "version", false, "print version and exit")
Expand All @@ -38,6 +39,7 @@ func main() {
flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode")
flag.StringVar(&meshNetworkName, "mesh-network-name", "weave", "network name to create in mesh mode")
flag.BoolVar(&noMulticastRoute, "no-multicast-route", false, "do not add a multicast route to network endpoints")
flag.BoolVar(&removeNetwork, "remove-network", false, "remove mesh network and exit")

flag.Parse()

Expand All @@ -48,16 +50,25 @@ func main() {

SetLogLevel(logLevel)

Log.Println("Weave plugin", version, "Command line options:", os.Args[1:])

// API 1.21 is the first version that supports docker network commands
dockerClient, err := docker.NewVersionedClientFromEnv("1.21")
if err != nil {
Log.Fatalf("unable to connect to docker: %s", err)
} else {
Log.Info(dockerClient.Info())
}

if removeNetwork {
if _, err = dockerClient.Client.NetworkInfo(meshNetworkName); err == nil {
err = dockerClient.Client.RemoveNetwork(meshNetworkName)
if err != nil {
Log.Fatalf("unable to remove network: %s", err)
}
}
os.Exit(0)
}

Log.Println("Weave plugin", version, "Command line options:", os.Args[1:])
Log.Info(dockerClient.Info())

var globalListener, meshListener net.Listener
endChan := make(chan error, 1)
if address != "" {
Expand Down
8 changes: 8 additions & 0 deletions weave
Expand Up @@ -1712,7 +1712,14 @@ launch_plugin() {
$PLUGIN_IMAGE "$@")
}

remove_plugin_network() {
docker run --rm --net=host \
-v /var/run/docker.sock:/var/run/docker.sock \
$PLUGIN_IMAGE --remove-network
}

stop_plugin() {
remove_plugin_network
stop $PLUGIN_CONTAINER_NAME "Plugin"
}

Expand Down Expand Up @@ -2146,6 +2153,7 @@ EOF
;;
reset)
[ $# -eq 0 ] || usage
remove_plugin_network || echo "WARNING: docker may hang in this state; re-launch weave and remove attached containers before shutting down" >&2
warn_if_stopping_proxy_in_env
call_weave DELETE /peer >/dev/null 2>&1 || true
for NAME in $PLUGIN_CONTAINER_NAME $CONTAINER_NAME $PROXY_CONTAINER_NAME ; do
Expand Down

0 comments on commit ecf4a82

Please sign in to comment.