-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from waitspring/Kafka
Kafka
- Loading branch information
Showing
2 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.