From cdd59e6ebbdfaf38e7c98dab48ca26c1130d87c1 Mon Sep 17 00:00:00 2001 From: Dan Caseley Date: Wed, 4 Aug 2021 22:27:37 +0100 Subject: [PATCH] Add scripts for dropping and readding nodes to the cluster --- block_node_from_cluster.sh | 22 ++++++++++++++++++++++ reset_cluster_blocking.sh | 12 ++++++++++++ unblock_node_from_cluster.sh | 13 +++++++++++++ 3 files changed, 47 insertions(+) create mode 100755 block_node_from_cluster.sh create mode 100755 reset_cluster_blocking.sh create mode 100755 unblock_node_from_cluster.sh diff --git a/block_node_from_cluster.sh b/block_node_from_cluster.sh new file mode 100755 index 0000000..89bb32e --- /dev/null +++ b/block_node_from_cluster.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +#Parameter NODE is the ID of the node you wish to drop from the cluster +#Example usage: `./remove_node_from_cluster.sh 1` to remove node xmpp1 + +NODE=$1 +CONTAINER_TO_REMOVE=openfire-docker-compose_xmpp"$NODE"_1 +CONTAINER_NAME=pumba_node"$NODE" + +echo "About to be removed from cluster: $CONTAINER_TO_REMOVE" + +docker run -d --rm \ + --name "$CONTAINER_NAME" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + gaiaadm/pumba netem --tc-image fishbowler/iproute2 --target 172.60.0.10 --target 172.60.0.20 --target 172.60.0.30 \ + --duration 24h \ + loss --percent 100 \ + "$CONTAINER_TO_REMOVE" + +sleep 1s + +[[ $(docker ps --filter "name=$CONTAINER_NAME" --format '{{.Names}}') == "$CONTAINER_NAME" ]] || (echo "Failed to block traffic. The cluster likely needs restarting" && exit 1) \ No newline at end of file diff --git a/reset_cluster_blocking.sh b/reset_cluster_blocking.sh new file mode 100755 index 0000000..c980b9f --- /dev/null +++ b/reset_cluster_blocking.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +stop_if_exists(){ + CONTAINER_NAME=$1 + [[ $(docker ps --filter "name=$CONTAINER_NAME" --format '{{.Names}}') == "$CONTAINER_NAME" ]] && docker stop "$CONTAINER_NAME" +} + +stop_if_exists "pumba_node1" +stop_if_exists "pumba_node2" +stop_if_exists "pumba_node3" + +exit 0 \ No newline at end of file diff --git a/unblock_node_from_cluster.sh b/unblock_node_from_cluster.sh new file mode 100755 index 0000000..0460916 --- /dev/null +++ b/unblock_node_from_cluster.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +NODE=$1 +CONTAINER_NAME=pumba_node"$NODE" + +[[ $(docker ps --filter "name=$CONTAINER_NAME" --format '{{.Names}}') == "$CONTAINER_NAME" ]] \ + && CONTAINER_EXISTS=1 || CONTAINER_EXISTS=0 + +if [ $CONTAINER_EXISTS == 1 ]; then + docker stop "$CONTAINER_NAME" +else + echo "No container to remove. Are you sure this node was blocked?" +fi