每5分钟检查一次,如果不在线就重启
#!/bin/bash count=`ps axu | grep kafka_2.11-1.0.0|grep -v grep|wc -l` echo "process count => "$count if [ "$count" != 0 ];then echo "kafka is running " else echo "kafka not running" #启动 kafka echo "开始启动 zookeeper...." sh /home/sol/kafka_2.11-1.0.0/bin/zookeeper-server-start.sh -daemon /home/sol/kafka_2.11-1.0.0/config/zookeeper.properties sleep 10; echo "开始启动 kafka...." sh /home/sol/kafka_2.11-1.0.0/bin/kafka-server-start.sh -daemon /home/sol/kafka_2.11-1.0.0/config/server.properties echo "kafka 启动成功" fi #crontab -e #*/5 * * * * /home/sol/startkafka.sh > /tmp/startkafka.log 2>&1 #startkafka.sh 不能放在 kafka_2.11-1.0.0 里面,否则 grep kafka_2.11-1.0.0 的count 会有数量 #grep kafka_2.11-1.0.0 最好不要写 grep kafka ,防止 count 有值
红字 kafka 可以换成 tomcat 等其它应用