forked from MariusCC/chef-bcpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-vip.sh
executable file
·32 lines (32 loc) · 1004 Bytes
/
cluster-vip.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
#!/bin/bash
if [[ -z "$1" ]]; then
if [[ -d environments ]]; then
ENVIRONMENTS=`ls -lt environments/*.json | wc -l`
else
echo "Usage: VIP not specified and can't find environment directory"
exit
fi
if (($ENVIRONMENTS == 1)); then
VIP=`grep -i vip environments/*.json | awk '{print $3}' | awk '{print substr($0, 2, length() - 3)}'`
echo "VIP from environment = $VIP"
else
echo "Usage: VIP not specified and more than one environment file found"
exit
fi
else
VIP=`grep -i vip environments/"$1".json | awk '{print $3}' | awk '{print substr($0, 2, length() - 3)}'`
echo "VIP IP address : $VIP"
fi
if [[ ! -z `which fping` ]]; then
# fping fails faster than ping
UP=`fping -aq "$VIP" | awk '{print $1}'`
else
UP=`ping -c1 "$VIP" | grep ttl | awk '{print $4}'`
fi
if [[ ! -z "$UP" ]]; then
MAC=`arp -n $VIP | grep ether | awk '{print $3}'`
HOST=`grep "$MAC" cluster.txt`
echo "VIP is currently : $HOST"
else
echo "$VIP appears to be down"
fi