Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize restart and self-start in kafka

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

#! / bin/sh

# ps-ef | grep $proc_name | grep-v grep | awk'{print $2}'

Source / etc/profile

Proc_dir= "/ data/modules/kafka_2.12-1.1.1" # Program directory

Proc_name= "kafka.Kafka" # process name

File_name= "/ data/lzmhtest/crontab/kafka/kafka.log" # log file

Number=ps-ef | grep $proc_name | grep-v grep | wc-l

PIDS=$ (ps ax | grep $proc_name | grep java | grep-v grep | awk'{print $1}')

If [$number-eq 0] # determines whether a process exists

Then

# cd / data/modules/kafka_2.12-1.1.1/bin

Sh $proc_dir/bin/kafka-server-start.sh-daemon $proc_dir/config/server.properties # restart the process

Pid=$ (ps ax | grep $proc_name | grep java | grep-v grep | awk'{print $1}') # get the new process number

Echo "service encountered an exception. In the process of restarting." [$(date +'% F% HRV% MRV% S')] > > $file_name

Echo "Service startup completed" PID: $pid [$(date +'% F% HRV% MRV% S')] > > $file_name # record the new process number and restart time

Else

Echo "kafka working normally" [$(date +'% F% HVA% MRV% S')] "pid:" $PIDS > > $file_name

Fi

Here is the cronta timing script; I wrote a patrol every minute.

/ 1 * lzmhqa / bin/sh / data/lzmhtest/crontab/kafka/kafka.sh

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 221

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report