-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhealthcheck.sh
executable file
·54 lines (43 loc) · 1.39 KB
/
healthcheck.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
#!/bin/bash
# check if expected ports are open
exitcode=0
ports=(6000 7687 7474)
if [ "$NEO4J_dbms_mode" == "CORE" ]; then
ports+=(5000)
ports+=(7000)
fi
for p in ${ports[@]}; do
nc -w 1 -zv $(hostname) $p
exitcode=$((exitcode+$?))
done
if [ $exitcode -ne 0 ]; then
exit $exitcode
fi
# query to get list of nodes in the format:
# http, role
# "http://10.0.y.x:7474", {"neo4j":"LEADER","system":"FOLLOWER"}
# "http://10.0.y.x:7474", {"neo4j":"FOLLOWER","system":"FOLLOWER"}
# "http://10.0.y.x:7474", {"neo4j":"FOLLOWER","system":"LEADER"}
COLUMNS="http, databases"
QUERY="call dbms.cluster.overview() YIELD addresses, databases return addresses[1] as $COLUMNS;"
## TODO: fix healthcheck command
# save nodes as array
readarray -t nodes < <(echo $QUERY | /var/lib/neo4j/bin/cypher-shell --non-interactive --format plain -u neo4j -p $NEO4J_ADMIN_PASSWORD -a bolt://localhost:7687 2>&1)
if [ "$?" -ne 0 ]; then
echo "Query $QUERY failed with error:"
echo "${nodes[@]}"
exit 1
fi
if [ "${nodes[0]}" != "$COLUMNS" ]; then
echo "Query response not in the expected format:"
echo "${nodes[@]}"
exit 1
fi
nodes=("${nodes[@]:1}") # remove first element of array, which is word $COLUMNS
# check if this is one node cluster
if [ "${#nodes[@]}" -lt 2 ]; then
echo "Looks like this node not a part of the cluster. List of nodes:"
echo "${nodes[@]}"
exit 1
fi
exit 0