Exit when launching plugin-v2 if node is not active in Swarm
We retrieve the list of swarm masters for peer discovery when launching plugin-v2, thus the node should belong to any Swarm when enabling the plugin.
This commit is contained in:
1 parent
4a708c2a82
commit
09606db9c3
2 files changed
+15
-2
No files matched your search
@@ -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"
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user