-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkCassandra.sh
executable file
·89 lines (69 loc) · 2.36 KB
/
checkCassandra.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
#set -x
#
#------------------------------
#
# Import settings
#
# Git branch
. ./settings.sh
# WriteLog() function
. ./timestampLogger.sh
#
#------------------------------
#
# Constants
#
BUILD_HOME=~/build/CE/platform/build
LONG_DATE=$(date "+%Y-%m-%d_%H-%M-%S")
CASSANDRA_CHECK_LOG_FILE=${OBT_LOG_DIR}/CheckCassandra-${LONG_DATE}.log
tryCount=2
#
#------------------------------
#
# Check the state of Cassandra Server
#
WriteLog "Start Cassandra Server check..." "${CASSANDRA_CHECK_LOG_FILE}"
# Check if Cassandra installed
if type "cqlsh" &> /dev/null
then
unset -v JAVA_HOME
while [[ $tryCount -ne 0 ]]
do
WriteLog "Try count: ${tryCount}" "${CASSANDRA_CHECK_LOG_FILE}"
cassandraState=$( cqlsh -e "show version;" -u cassandra -p cassandra 2>/dev/null | grep 'Cassandra')
if [[ -z $cassandraState ]]
then
WriteLog "It doesn't respond to version query. Check if it is already running." "${CASSANDRA_CHECK_LOG_FILE}"
cassandraPID=$( ps ax | grep '[c]assandra' | awk '{print $1}' )
if [[ -n "$cassandraPID" ]]
then
WriteLog "It is running (pid: ${cassandraPID}), kill it. " "${CASSANDRA_CHECK_LOG_FILE}"
sudo kill -9 ${cassandraPID}
sleep 10
sudo rm -rf /var/lib/cassandra/*
fi
WriteLog "Stoped! Start it!" "${CASSANDRA_CHECK_LOG_FILE}"
${SUDO} cassandra > /dev/null 2>&1
sleep 30
tryCount=$(( $tryCount-1 ))
continue
else
WriteLog "Cassandra is up!" "${CASSANDRA_CHECK_LOG_FILE}"
break
fi
done
if [[ $tryCount -eq 0 ]]
then
WriteLog "Cassandra doesn't start! Give up and send Email to Agyi!" "${CASSANDRA_CHECK_LOG_FILE}"
# send email to Agyi
echo "Cassandra doesn't start in $0 !" | mailx -s "Problem with Cassandra" -u $USER ${ADMIN_EMAIL_ADDRESS}
fi
else
WriteLog "Cassandra not installed in this sysytem! Give up and send Email to Agyi!" "${CASSANDRA_CHECK_LOG_FILE}"
# send email to Agyi
echo "Cassandra not installed in this sysytem!" | mailx -s "Problem with Cassandra" -u $USER ${ADMIN_EMAIL_ADDRESS}
fi
WriteLog "End of Cassandra Server check." "${CASSANDRA_CHECK_LOG_FILE}"
set +x