-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.sh
59 lines (43 loc) · 934 Bytes
/
monitor.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
#!/bin/bash
LOCKFILE="/tmp/sphinx_monitor.lock"
lockfile -r 0 $LOCKFILE || exit 1
RESTART=0
MIN=20000
DATE=`date`
QUERY="select count(*) as c from listing2 where match('100')"
IP=`/sbin/ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -1`
PORT="9309"
ITEMS=`timeout 5s mysql -B -h $IP -P $PORT -u test -e "$QUERY" -A -r -N`
if [ $? == '124' ]
then
echo $DATE 'Timeout'
RESTART=1
fi
if [ "$ITEMS" == "" ]
then
echo $DATE 'Empty result'
RESTART=1
else
if [ "$ITEMS" -lt "$MIN" ]
then
echo $DATE Less then $MIN items
RESTART=1
fi
fi
if [ "$RESTART" -eq "1" ]
then
echo $DATE Restarting sphinx
/etc/init.d/sphinxsearch stop
sleep 10
if pgrep -x "searchd"
then
echo killing all searchd
killall -s SIGKILL searchd
sleep 2
fi
/etc/init.d/sphinxsearch start
sleep 180
else
echo $DATE $ITEMS items in sphinx $IP >> /var/log/sphinx_monitor.log
fi
rm -f $LOCKFILE