diff --git a/docs/reference/scripts-library.md b/docs/reference/scripts-library.md index 1a1ce1ee8..f5ddaeb4b 100644 --- a/docs/reference/scripts-library.md +++ b/docs/reference/scripts-library.md @@ -214,14 +214,26 @@ Usage: `notify_slack_danger ` ## swarm -### this_swarm_node +### all_swarm_nodes -Print the name of the runngin node. +Print the name of all the nodes in the swarm -Usage: `THIS=$(this_swarm_node)` +Usage: `ALL=$(all_swarm_nodes)` + +### docker_id_from_name + +Print the id of the docker with a matching name + +Usage: `DOCKER_ID=$(docker_id_from_name mapserver)` ### other_swarm_nodes -Print the name of the other nodes in the swarm. +Print the name of the all nodes in the swarm minus the node we're running on. Usage: `OTHER=$(other_swarm_nodes)` + +### this_swarm_node + +Print the name of the running node. + +Usage: `THIS=$(this_swarm_node)` diff --git a/scripts/swarm.sh b/scripts/swarm.sh index 6dab9d011..3e834227b 100644 --- a/scripts/swarm.sh +++ b/scripts/swarm.sh @@ -6,6 +6,15 @@ this_swarm_node() { uname -n } +all_swarm_nodes() { + docker node ls --format "{{.Hostname}}" +} + other_swarm_nodes() { - docker node ls | grep Ready | grep -v $(this_swarm_node) | awk '{ print $2 }' + docker node ls --format "{{.Hostname}}" | grep -v $(this_swarm_node) +} + +docker_id_from_name() { + local NAME=$1 + docker ps --filter "status=running" --filter "name=${NAME}" --format "{{.ID}}" | head -1 }