-
Notifications
You must be signed in to change notification settings - Fork 1
/
kill-node.sh
executable file
·60 lines (53 loc) · 1.59 KB
/
kill-node.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#echo "kill node sub script"
function usage
{
echo -e "\nKill Nodes Usage: \n
--stop Stop docker containers. Value should be list of docker containers name or id with comma seperated value (eg: --stop knode1,zoo1)
--remove Remove docker containers. Value should be list of docker containers name or id with comma seperated value (eg: --remove knode1,zoo1)
--all Remove all docker containers related to kafkaspinner.
-h | --help Help\n";
}
function getContainersArray
{
CONTAINERS=()
IFS=','
read -ra TEMP_ARRAY <<< "$1"
CONTAINERS=( "${TEMP_ARRAY[@]}" )
}
function killDockerContainers
{
CLUSTER_CONTAINER_LIST+=($(docker ps -a -q))
for i in "${CLUSTER_CONTAINER_LIST[@]}"
do
hostname=$(docker inspect -f '{{ .Config.Hostname }}' $i)
if [[ "$hostname" == *knode* || "$hostname" == *zoo* ]]; then
echo "killing $hostname"
#docker stop $hostname
docker rm -f $hostname
fi
done
}
while [ "$1" != "" ]; do
case $1 in
--stop) shift
getContainersArray $1
echo "Stopping containers ${CONTAINERS[@]}"
docker stop "${CONTAINERS[@]}"
;;
--remove) shift
getContainersArray $1
echo "Killing containers ${CONTAINERS[@]}"
docker rm -f "${CONTAINERS[@]}"
;;
--all)
killDockerContainers
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done