Skip to content

Instantly share code, notes, and snippets.

@arcezd
Created February 26, 2019 20:30
Show Gist options
  • Save arcezd/74db57afa95517819855bfbabc064882 to your computer and use it in GitHub Desktop.
Save arcezd/74db57afa95517819855bfbabc064882 to your computer and use it in GitHub Desktop.
Check docker swarm status
#!/bin/bash
if [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "inactive" ]; then
echo "Node is not in a swarm cluster"
exit 0
elif [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "active" ]; then
echo "Node is in a swarm and healthy"
elif [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "pending" ]; then
echo "Node is in a swarm but no quorum"
elif [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "locked" ]; then
echo "Node is in a swarm but the cluster is locked"
elif [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "error" ]; then
echo "Unknown error state"
else
echo "Unknown state"
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment