Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Kafka Kafka Run Class Exec

From Leeroopedia


Knowledge Sources
Domains Operations, Server_Administration
Last Updated 2026-02-09 12:00 GMT

Overview

Concrete tool for launching a Kafka JVM process with assembled options provided by kafka-run-class.sh.

Description

The process launch section of kafka-run-class.sh is the terminal command that starts the actual JVM process. It combines all JVM options (heap, performance, GC logging, JMX, Log4j, custom) with the classpath and the target main class. In daemon mode, it uses nohup with output redirected to a console log. In native mode, it executes a pre-compiled binary directly.

Usage

This is the final section of kafka-run-class.sh and is not invoked directly. The execution mode is controlled by the -daemon flag passed by the calling script.

Code Reference

Source Location

  • Repository: Apache Kafka
  • File: bin/kafka-run-class.sh
  • Lines: L345-354

Signature

# Foreground execution:
exec "$JAVA" $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS \
  $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_CMD_OPTS \
  -cp "$CLASSPATH" $KAFKA_OPTS "$@"

# Daemon execution:
nohup "$JAVA" $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS \
  $KAFKA_GC_LOG_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_CMD_OPTS \
  -cp "$CLASSPATH" $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null &

# Native execution:
exec "$base_dir"/kafka.Kafka "$@"

Import

# Invoked automatically by kafka-run-class.sh
# Controlled by -daemon flag and KAFKA_MODE=native

I/O Contract

Inputs

Name Type Required Description
JAVA env Yes Path to Java binary
CLASSPATH env Yes Assembled classpath from previous step
All KAFKA_*_OPTS env Yes Assembled JVM options from previous step
DAEMON_MODE flag No If set, use nohup for background execution
KAFKA_MODE env No If "native", use pre-compiled binary
$@ args Yes Main class name and its arguments

Outputs

Name Type Description
JVM process process Running Kafka JVM (foreground or daemon)
Console output file In daemon mode, written to $CONSOLE_OUTPUT_FILE

Usage Examples

Standard Foreground Launch

# Via kafka-server-start.sh (foreground)
bin/kafka-server-start.sh config/server.properties
# Internally executes: exec java -Xmx1G -Xms1G ... -cp "$CLASSPATH" kafka.Kafka config/server.properties

Daemon Launch

# Via kafka-server-start.sh with -daemon flag
bin/kafka-server-start.sh -daemon config/server.properties
# Internally executes: nohup java ... kafka.Kafka config/server.properties > console.log 2>&1 &

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment