diff --git a/prog/net-plugin/launch.sh b/prog/net-plugin/launch.sh index 818f66f7..a372be13 100755 --- a/prog/net-plugin/launch.sh +++ b/prog/net-plugin/launch.sh @@ -16,10 +16,16 @@ echo "Starting launch.sh" # Check if the IP range overlaps anything existing on the host /usr/bin/weaveutil netcheck $IPALLOC_RANGE weave -# TODO(mp) add wait for swarm +STATUS=0 +/usr/bin/weaveutil is-swarm-manager 2>/dev/null || STATUS=$? +if [ $STATUS -eq 0 ]; then + IS_SWARM_MANAGER=1 +elif [ $STATUS -eq 20 ]; then + echo "Host swarm is not \"active\"; exiting." >&2 + exit 1 +fi SWARM_MANAGER_PEERS=$(/usr/bin/weaveutil swarm-manager-peers) -! /usr/bin/weaveutil is-swarm-manager || IS_SWARM_MANAGER=1 # Prevent from restoring from a persisted peers list rm -f "/restart.sentinel" diff --git a/prog/weaveutil/swarm.go b/prog/weaveutil/swarm.go index fbec29e9..6131b3a9 100644 --- a/prog/weaveutil/swarm.go +++ b/prog/weaveutil/swarm.go @@ -2,8 +2,10 @@ package main import ( "fmt" + "os" "strings" + "github.com/docker/docker/api/types/swarm" "github.com/fsouza/go-dockerclient" "github.com/pkg/errors" ) @@ -16,6 +18,11 @@ func isSwarmManager(args []string) error { return err } + // hack-y way to denote that a node does not belong to any swarm + if info.Swarm.LocalNodeState != swarm.LocalNodeStateActive { + os.Exit(20) + } + if !info.Swarm.ControlAvailable { return fmt.Errorf("node is not a manager") }