-
Notifications
You must be signed in to change notification settings - Fork 11
/
node-down
executable file
·78 lines (65 loc) · 2.17 KB
/
node-down
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Use this script to down one or more Akka cluster nodes. The command line parameters must be from 1 to 9.
# Nodes are downed via a management node. The management node defaults to 1. The management node can be
# changed using the via option - options -v or --via.
# Example - from management node 2, down node 5.
# ./akka node down 2 5
# Example - from default management node 1, down nodes 6 8 9.
# ./akka node down 6 8 9
# Example - from management node 6, down node 6.
# ./akka node down --via 6 6
# Example - from default management node 1, down nodes 6 8 9. And node 6 8 9 down themselves.
# ./akka node down 6 8 9 -v 6 6 -v 8 8 -v 9 9
usage() {
echo "Usage: $0 [-v|--via M] N... - Down cluster nodes N... via mgmt node M, 6 8 9 -v 6 6 -v 8 8 -v 9 9. M default is 1." ; exit 1
}
downNode() {
mgmtPort="855"$1
node=$2
nodePort="255"$node
httpStatus=$(curl --write-out %{http_code} --max-time 5 --silent --output /dev/null http://localhost:"$mgmtPort"/cluster/members)
if [[ $httpStatus == 200 ]] ; then
echo "Down node $node on $localhostName:$nodePort via Akka management $localhostName:$mgmtPort"
curl --silent -X PUT -F "operation=down" http://localhost:"$mgmtPort"/cluster/members/cluster@"$localhostName":"$nodePort" --output /dev/null
else
echo "Management port $mgmtPort, HTTP response $httpStatus"
fi
}
getLocalhostName() {
if hash pfctl 2>/dev/null; then
ifconfig | grep "127.0.0.2" > /dev/null
localhost2=$?
elif hash ip 2>/dev/null; then
ip address | grep "127.0.0.2" > /dev/null
localhost2=$?
else
localhost2=1
fi
if [ $localhost2 -eq 0 ] ; then
export localhostName="127.0.0.2"
else
export localhostName="127.0.0.1"
fi
}
[ $# -eq 0 ] && usage
via=1
while [[ $# -gt 0 ]]; do
arg=$1
shift
if [ "$arg" = "-v" ] || [ "$arg" = "--via" ]; then
v=$1
shift
if [[ $v =~ ^[1-9]$ ]] ; then
via=$v
else
echo "Via node number '$v' invalid. Must be 1-9."
usage
fi
elif [[ $arg =~ ^[1-9]$ ]] ; then
getLocalhostName
downNode "$via" "$arg"
else
echo "Argument '$arg' is invalid."
usage
fi
done