Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize restart and self-start in kafka

Shulou Source: shulou.com Published: 2022-06-03 05:21:25 09月21日 Update

#! / 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

Tags: Process service file log time in progress directory program script run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Apple NVidia Huawei