This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
2020-03-10 19:52:21 +08:00

31 lines
1.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
#修改BASE_DIR为安装的路径
#启动命令端口可自行指定
#JMX_PORT=9191 nohup $BASE_DIR/bin/kafka-server-start.sh $BASE_DIR/config/server.properties > /dev/null 2>&1 &
PRO_NAME=Kafka
BASE_DIR=$1
VERSION="kafka_2.11-1.0.0"
#string=`cat $BASE_DIR/$VERSION/config/server.properties | grep broker.id`
#array=(${string//=/ })
#echo ${array[1]}
#ssh root@192.168.40.123 "source /etc/profile ; zkCli.sh ls /kafka/brokers/ids | grep -v 2181 | grep 4 | wc -l"
source /etc/profile
while true ; do
NUM=`jps | grep -w ${PRO_NAME} | grep -v grep |wc -l`
if [ "${NUM}" -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 &
OLD_NUM=`cat $BASE_DIR/$VERSION/logs/restart_sum.log`
RESTART_NUM=`expr $OLD_NUM + 1`
echo $RESTART_NUM > $BASE_DIR/$VERSION/logs/restart_sum.log
echo "`date "+%Y-%m-%d %H:%M:%S"` - kafka服务启动/异常重启 - 重启次数 -> $RESTART_NUM" >> $BASE_DIR/$VERSION/restart.log
#大于1杀掉所有进程重启
elif [ "${NUM}" -gt "1" ];then
killall -9 ${PRO_NAME}
fi
sleep 60
done