Skip to content

Commit

Permalink
Merge pull request #21 from waitspring/Kafka
Browse files Browse the repository at this point in the history
Kafka
  • Loading branch information
waitspring authored Aug 13, 2023
2 parents 358dd49 + 3d18cac commit d3e834e
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions Kafka/Template/kafka
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
# -*- coding: utf-8 -*-
#
# chkconfig: 35 98 98
#
#######################################################################################################################
# _ _ _ #
# | | | | | | #
# | | __, | | | | __, #
# |/_) / | |/ |/_) / | #
# | \_/\_/|_/|__/| \_/\_/|_/ #
# |\ #
# |/ #
#######################################################################################################################
#
# Location: /etc/init.d/kafka
# Usage:
# $ chkconfig kafka on
# $ service kafka { start | stop | restart }


source /etc/init.d/functions


# =====================================================================================================================
# Check prerequisite
# =====================================================================================================================
if [[ ${#} != 1 ]]; then
action "check parameter" /bin/false
exit 1
else
source ~/.bash_profile
cd $(dirname ${0})
fi

CONF=/etc/kafka/kraft/server.properties
EXEC=/usr/local/kafka/bin/kafka-server-start.sh
STOP=/usr/local/kafka/bin/kafka-server-stop.sh
USER=kafka
PORT=9092

if [[ ! -f ${CONF} ]]; then
action "check ${CONF}" /bin/false
exit 1
fi
if [[ ! -f ${EXEC} ]] || [[ ! -x ${EXEC} ]]; then
action "check ${EXEC}" /bin/false
exit 1
fi


# =====================================================================================================================
# Script main part
# =====================================================================================================================
start() {
if [[ $(netstat -elnptu | grep ${PORT} | wc -l) == 0 ]]; then
daemon --user ${USER} ${EXEC} -daemon ${CONF}
RETVAL=${?}
if [[ ${RETVAL} == 0 ]]; then
action "starting up kafka ..." /bin/true
else
action "starting up kafka ..." /bin/false
fi
return ${RETVAL}
else
if [[ $(ps aux | grep ${CONF} | grep -v grep | wc -l) == 0 ]]; then
echo "kafka port ${PORT} has been token ..."
return 1
else
action "starting up kafka ..." /bin/true
return 0
fi
fi
}

stop() {
if [[ $(netstat -elnptu | grep ${PORT} | wc -l) != 0 ]]; then
if [[ $(ps aux | grep ${CONF} | grep -v grep | wc -l) != 0 ]]; then
${STOP}
RETVAL=${?}
if [[ ${RETVAL} == 0 ]]; then
action "shutting down kafka ..." /bin/true
else
action "shutting down kafka ..." /bin/false
fi
return ${RETVAL}
fi
fi
action "shutting down kafka ..." /bin/true
return 0
}

status() {
if [[ $(netstat -elnptu | grep ${PORT} | wc -l) != 0 ]]; then
if [[ $(ps aux | grep ${CONF} | grep -v grep | wc -l) != 0 ]]; then
PID=$(ps aux | grep ${CONF} | grep -v grep | gawk '{ print $2 }')
echo "kafka (pid ${PID}) is running ..."
return 0
fi
fi
echo "kafka is not running ..."
return 0
}


# =====================================================================================================================
# Script main part
# =====================================================================================================================
case ${1} in
start )
start
;;
stop )
stop
;;
status )
status
;;
restart )
stop
sleep 5
start
;;
* )
echo $"Usage: ${0} { start | stop | status | restart }"
exit 2
;;
esac

exit 0
File renamed without changes.

0 comments on commit d3e834e

Please sign in to comment.