I'm having an issue creating my init script for Apache Kafka that I'm hoping someone can help me with. I've spent about 6 hours on it now, and I'm at a loss.
The problem I'm having is that the Java program that starts a Kafka server doesn't by default return control to the shell. It runs in the foreground. I couldn't find a way to call the Java class to have it return, so the logical thing to try was to throw an "&" at the end of the 'exec' line. While from a shell script this works as expected, when done within the service framework, it behaves differently. It *appears* as if the call to 'exec' with an "&" at the end somehow bypasses the service control and doesn't let the "start" section actually finish. It's a bit hard to describe. I've attached the init file to this post in hopes that there is something simple I'm doing wrong.
Here is the 'start' section of the script also:
Code: Select all
start() {
checkJava
[ -x $exec ] || exit 5
[ -f $CONF_FILE ] || exit 6
if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES
fi
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
daemon $daemonopts $exec daemon kafkaServer kafka.Kafka $CONF_FILE &
retval=$?
echo $retval
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
Code: Select all
root@n6[297]:/etc/init.d> service kafka status
kafka is stopped
root@n6[298]:/etc/init.d> service kafka start
Starting kafka: 0
root@n6[299]:/etc/init.d> service kafka status
kafka dead but subsys locked
Code: Select all
root@n6[434]:/etc/init.d> service kafka status
kafka is stopped
root@n6[435]:/etc/init.d> service kafka start
Starting kafka:
Code: Select all
root@n6[425]:~> ps -ef | grep kafka
root 1631 1062 0 21:50 pts/2 00:00:00 /usr/java/bin/java -Xmx512M -Xms512M -server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true -Xloggc:/opt/kafka/kafka/bin/../logs/zookeeper-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dlog4j.configuration=file:bin/../config/log4j.properties -cp :/opt/kafka/kafka/bin/../core/target/scala-2.8.0/*.jar:/opt/kafka/kafka/bin/../perf/target/scala-2.8.0/kafka*.jar:/opt/kafka/kafka/bin/../libs/jopt-simple-3.2.jar:/opt/kafka/kafka/bin/../libs/log4j-1.2.15.jar:/opt/kafka/kafka/bin/../libs/metrics-annotation-2.2.0.jar:/opt/kafka/kafka/bin/../libs/metrics-core-2.2.0.jar:/opt/kafka/kafka/bin/../libs/scala-compiler.jar:/opt/kafka/kafka/bin/../libs/scala-library.jar:/opt/kafka/kafka/bin/../libs/slf4j-api-1.7.2.jar:/opt/kafka/kafka/bin/../libs/slf4j-simple-1.6.4.jar:/opt/kafka/kafka/bin/../libs/snappy-java-1.0.4.1.jar:/opt/kafka/kafka/bin/../libs/zkclient-0.3.jar:/opt/kafka/kafka/bin/../libs/zookeeper-3.3.4.jar:/opt/kafka/kafka/bin/../kafka_2.8.0-0.8.0.jar org.apache.zookeeper.server.quorum.QuorumPeerMain config/zookeeper.properties
root 1661 1045 0 21:51 pts/1 00:00:00 /bin/sh /sbin/service kafka start
root 1666 1661 0 21:51 pts/1 00:00:00 /bin/sh /etc/init.d/kafka start
root 1672 1666 0 21:51 pts/1 00:00:00 /bin/bash -c ulimit -S -c 0 >/dev/null 2>&1 ; /opt/kafka/kafka/bin/kafka-run-class.sh daemon kafkaServer kafka.Kafka /opt/kafka/kafka/config/server.properties
root 1673 1672 2 21:51 pts/1 00:00:01 java -Xmx256M -server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true -Xloggc:/opt/kafka/kafka/bin/../logs/kafkaServer-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8888 -Dlog4j.configuration=file:/opt/kafka/kafka/config/log4j.properties -cp :/opt/kafka/kafka/bin/../core/target/scala-2.8.0/*.jar:/opt/kafka/kafka/bin/../perf/target/scala-2.8.0/kafka*.jar:/opt/kafka/kafka/bin/../libs/jopt-simple-3.2.jar:/opt/kafka/kafka/bin/../libs/log4j-1.2.15.jar:/opt/kafka/kafka/bin/../libs/metrics-annotation-2.2.0.jar:/opt/kafka/kafka/bin/../libs/metrics-core-2.2.0.jar:/opt/kafka/kafka/bin/../libs/scala-compiler.jar:/opt/kafka/kafka/bin/../libs/scala-library.jar:/opt/kafka/kafka/bin/../libs/slf4j-api-1.7.2.jar:/opt/kafka/kafka/bin/../libs/slf4j-simple-1.6.4.jar:/opt/kafka/kafka/bin/../libs/snappy-java-1.0.4.1.jar:/opt/kafka/kafka/bin/../libs/zkclient-0.3.jar:/opt/kafka/kafka/bin/../libs/zookeeper-3.3.4.jar:/opt/kafka/kafka/bin/../kafka_2.8.0-0.8.0.jar kafka.Kafka /opt/kafka/kafka/config/server.properties
root 1722 1708 0 21:51 pts/0 00:00:00 grep kafka
Help is much appreciated. I know this can be done.
Thank you for your help.
Chris