-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka
executable file
·135 lines (108 loc) · 2.37 KB
/
kafka
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /bin/bash
# /etc/init.d/kafka: start the kafka daemon.
# chkconfig: - 80 20
# description: kafka
KAFKA_START_SH=$KAFKA_HOME/bin/kafka-server-start.sh
KAFKA_STOP_SH=$KAFKA_HOME/bin/kafka-server-stop.sh
KAFKA_CONSOLE_DIR=/data/app/log
KAFKA_CONSOLE_LOG=${KAFKA_CONSOLE_DIR}/server.log
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
prog=kafka
DESC="kafka daemon"
RETVAL=0
STARTUP_WAIT=30
SHUTDOWN_WAIT=30
mkdir -p $(dirname $KAFKA_PIDFILE)
# Source function library.
. /lib/lsb/init-functions
DATE=$(date '+%Y-%m-%d %H:%M:%S')
start() {
echo -n $"${DATE} Starting $prog: "
# Create pid file
if [ -f $KAFKA_PIDFILE ]; then
read ppid < $KAFKA_PIDFILE
if [ $(ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null) -eq '1' ]; then
echo -n "$prog is already running"
log_failure_msg "[failure]"
echo
return 1
else
rm -f $KAFKA_PIDFILE
fi
fi
# Run daemon
cd $KAFKA_HOME
$KAFKA_START_SH -daemon $KAFKA_HOME/config/kraft/server.properties
PID=$(ps ax | grep -i 'kafka.Kafka' | grep -v grep | awk '{print $1}')
echo $PID > $KAFKA_PIDFILE
count=0
launched=false
sleep 1
until [ $count -gt $STARTUP_WAIT ]
do
grep 'Kafka Server started' $KAFKA_CONSOLE_LOG > /dev/null
if [ $? -eq 0 ] ; then
launched=true
break
fi
sleep 1
let count=$count+1;
done
if [ $launched = 'true' ] ; then
log_success_msg "[OK]"
else
log_failure_msg "[failure]"
fi
echo
return 0
}
stop() {
echo -n $"${DATE} Stopping $prog: "
$KAFKA_STOP_SH
rm -rf $KAFKA_PIDFILE
log_success_msg "[OK]"
echo
}
reload() {
stop
start
}
restart() {
stop
start
}
status() {
if [ -f $KAFKA_PIDFILE ]; then
read ppid < $KAFKA_PIDFILE
if [ $(ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null) -eq '1' ]; then
echo "$prog is running (pid $ppid)"
return 0
else
echo "$prog dead but pid file exists"
return 1
fi
fi
echo "$prog is not running"
return 3
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|status}"
exit 1
esac
exit $?