blob: 12d8f85109be4e46b04a5d825b648af28a26f637 (
plain)
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
|
#!/bin/bash
source /etc/profile
BASE_DIR=/home/tsg/olap
VERSION=kafka_2.11-1.0.0
function checkLogFiles(){
if [ ! -d "$BASE_DIR/$VERSION/logs/reslogs/" ];then
mkdir -p $BASE_DIR/$VERSION/logs/reslogs
fi
if [ ! -f "$BASE_DIR/$VERSION/logs/restart_sum" ];then
echo 0 > $BASE_DIR/$VERSION/logs/restart_sum
fi
}
checkLogFiles
function set_log(){
OLD_NUM=`cat $BASE_DIR/$VERSION/logs/restart_sum`
RESTART_NUM=`expr $OLD_NUM + 1`
echo $RESTART_NUM > $BASE_DIR/$VERSION/logs/restart_sum
if [ $OLD_NUM -eq "0" ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` - kafka服务初次启动" >> $BASE_DIR/$VERSION/logs/restart.log
else
RESLOG_NAME=restart_log_`date "+%Y%m%d_%H%M%S"`
echo "`date "+%Y-%m-%d %H:%M:%S"` - kafka服务异常重启 - 重启次数 -> $RESTART_NUM ;错误日志归纳文件路径:$BASE_DIR/$VERSION/reslogs/$RESLOG_NAME" >> $BASE_DIR/$VERSION/logs/restart.log
tail -n 50000 $BASE_DIR/$VERSION/logs/server.log | egrep "ERROR|WARN" >> $BASE_DIR/$VERSION/logs/reslogs/$RESLOG_NAME
fi
}
while true ; do
PROCESS=`jps | grep -w Kafka | grep -v grep |wc -l`
PORT=`netstat -anlp | egrep "9092|9094|9095" | grep "LISTEN" | wc -l`
if [ $PORT -ne "3" ];then
if [ $PROCESS -lt "1" ];then
JMX_PORT=9191 nohup $BASE_DIR/$VERSION/bin/kafka-server-start.sh $BASE_DIR/$VERSION/config/server.properties > /dev/null 2>&1 &
set_log
fi
#else
# echo "`date "+%Y-%m-%d %H:%M:%S"` - Kafka端口未监听进程存在,判断为僵尸进程,开始kill本机Kafka进程" >> $BASE_DIR/$VERSION/logs/restart.log
# jps | grep Kafka | awk '{print $1}' | xargs kill -9
fi
sleep 60
done
|