cd $(dirname $0) source ~/.bash_profile count_zoo=`ps -ef | grep "config/zookeeper.properties" | grep -v grep | wc -l` count_kafka=`ps -ef | grep "config/server.properties" | grep -v grep | wc -l` count_2181=`netstat -antp | grep ":2181" | grep -v grep | wc -l` count_9092=`netstat -antp | grep ":9092" | grep -v grep | wc -l` echo $count_zoo if [ $count_zoo -eq 0 ] || [ $count_kafka -eq 0 ] || [ $count_2181 -eq 0 ] || [ $count_9092 -eq 0 ];then bin/kafka-server-stop.sh bin/zookeeper-server-stop.sh nohup bin/zookeeper-server-start.sh config/zookeeper.properties& nohup bin/kafka-server-start.sh config/server.properties & fi
cd $(dirname $0) count=`ps -ef | grep "python watch_file_temp.py" | grep -v grep | wc -l` count_9092=`netstat -antp | grep ":9092" | grep -v grep | wc -l` if [ $count -eq 0 ] || [ $count_9092 -eq 0 ];then killall -9 watch_file_temp.py nohup /usr/bin/python watch_file_temp.py & fi
ps -ef | grep kafka | awk '{print $2}' | xargs kill -9
本文介绍了一段Shell脚本,用于检查Kafka和Zookeeper服务的状态,并在发现服务未运行时自动进行重启。此外,还监控了一个Python文件监控程序的状态,并在必要时重启该程序。
4072





