52 lines
1.5 KiB
Bash
52 lines
1.5 KiB
Bash
#!/bin/sh
|
|
|
|
# Restart the kafka comsumer service
|
|
|
|
# 获取命令行参数
|
|
if [ $# -ne 1 ]; then
|
|
echo "Usage: $0 [start|stop|status|restart]"
|
|
exit 1
|
|
fi
|
|
|
|
if [ $1 == "start" ]; then
|
|
echo "Starting kafka comsumer..."
|
|
> log/kafka-comsumer.log # 清空 logs 文件
|
|
nohup ./kafka_comsumer >> logs 2>&1 &
|
|
echo "kafka comsumer started."
|
|
elif [ $1 == "stop" ]; then
|
|
echo "Stopping kafka comsumer..."
|
|
PID=$(ps -ef | grep kafka_comsumer | grep -v "grep" | awk '{print $2}')
|
|
if [ -z $PID ]; then
|
|
echo "kafka comsumer is not running."
|
|
exit 1
|
|
fi
|
|
ps -ef | grep kafka_comsumer | grep -v grep | awk '{print $2}' | xargs kill
|
|
echo "kafka comsumer stopped."
|
|
elif [ $1 == "status" ]; then
|
|
echo "kafka comsumer status:"
|
|
PID=$(ps -ef | grep kafka_comsumer | grep -v "grep" | awk '{print $2}')
|
|
if [ -z $PID ]; then
|
|
echo "kafka comsumer is not running."
|
|
else
|
|
echo "kafka comsumer is running."
|
|
fi
|
|
elif [ $1 == "restart" ]; then
|
|
echo "Restarting kafka comsumer..."
|
|
PID=$(ps -ef | grep kafka_comsumer | grep -v "grep" | awk '{print $2}')
|
|
if [ -n "$PID" ]; then
|
|
echo "kafka comsumer stoping."
|
|
kill $PID
|
|
fi
|
|
while [ -n "$PID" ]; do
|
|
sleep 1
|
|
PID=$(ps -ef | grep kafka_comsumer | grep -v "grep" | awk '{print $2}')
|
|
done
|
|
echo "kafka comsumer stoped."
|
|
> log/kafka-comsumer.log # 清空 logs 文件
|
|
nohup ./kafka_comsumer >> logs 2>&1 &
|
|
echo "kafka comsumer restarted."
|
|
else
|
|
echo "Usage: $0 [start|stop|status|restart]"
|
|
exit 1
|
|
fi
|