KAFKA-15471 [MINOR]: Fix backward-compatibility bug (#14996)

Fixes a backwards-compatibility issue in the KIP-979 change to the kafka-server-stop.sh script where it would not stop processes if run from a directory that differed from the directory where the processes were started form and the config file specified at start time was a relative path.

Reviewers: Ron Dagostino <rdagostino@confluent.io>
This commit is contained in:
Hailey Ni 2023-12-14 07:32:16 -08:00 committed by GitHub
parent b0e99b5593
commit 40e817eeff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 14 deletions

View File

@ -31,17 +31,6 @@ elif [[ "$OSNAME" == "OS400" ]]; then
PIDS=$(ps -Af | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $2}') PIDS=$(ps -Af | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $2}')
else else
PIDS=$(ps ax | grep ' kafka\.Kafka ' | grep java | grep -v grep | awk '{print $1}'| xargs) PIDS=$(ps ax | grep ' kafka\.Kafka ' | grep java | grep -v grep | awk '{print $1}'| xargs)
RelativePathToConfig=$(ps ax | grep ' kafka\.Kafka ' | grep java | grep -v grep | sed 's/--override property=[^ ]*//g' | awk 'NF>1{print $NF}' | xargs)
IFS=' ' read -ra RelativePathArray <<< "$RelativePathToConfig"
declare -a AbsolutePathToConfigArray
for ((i = 0; i < ${#RelativePathArray[@]}; i++)); do
AbsolutePathToConfig=$(readlink -f "${RelativePathArray[i]}")
if [ -z "$AbsolutePathToConfig" ]; then
echo "Can not find the configuration file in the current directory. Please make sure the kafka stop process and the start process are called in the same directory."
exit 1
fi
AbsolutePathToConfigArray+=("$AbsolutePathToConfig")
done
fi fi
if [ -z "$PIDS" ]; then if [ -z "$PIDS" ]; then
@ -51,14 +40,21 @@ else
if [ -z "$INPUT_PROCESS_ROLE" ] && [ -z "$INPUT_NID" ]; then if [ -z "$INPUT_PROCESS_ROLE" ] && [ -z "$INPUT_NID" ]; then
kill -s $SIGNAL $PIDS kill -s $SIGNAL $PIDS
else else
RelativePathToConfig=$(ps ax | grep ' kafka\.Kafka ' | grep java | grep -v grep | sed 's/--override property=[^ ]*//g' | awk 'NF>1{print $NF}' | xargs)
IFS=' ' read -ra PIDSArray <<< "$PIDS" IFS=' ' read -ra PIDSArray <<< "$PIDS"
for ((i = 0; i < ${#AbsolutePathToConfigArray[@]}; i++)); do IFS=' ' read -ra RelativePathArray <<< "$RelativePathToConfig"
for ((i = 0; i < ${#RelativePathArray[@]}; i++)); do
AbsolutePathToConfig=$(readlink -f "${RelativePathArray[i]}")
if [ -z "$AbsolutePathToConfig" ] ; then
echo "Can not find the configuration file in the current directory. Please make sure the kafka stop process and the start process are called in the same directory."
exit 1
fi
if [ -n "$INPUT_NID" ] ; then if [ -n "$INPUT_NID" ] ; then
keyword="node.id=" keyword="node.id="
NID=$(sed -n "/$keyword/ { s/$keyword//p; q; }" "${AbsolutePathToConfigArray[i]}") NID=$(sed -n "/$keyword/ { s/$keyword//p; q; }" "$AbsolutePathToConfig")
elif [ -n "$INPUT_PROCESS_ROLE" ] && [ -z "$INPUT_NID" ]; then elif [ -n "$INPUT_PROCESS_ROLE" ] && [ -z "$INPUT_NID" ]; then
keyword="process.roles=" keyword="process.roles="
PROCESS_ROLE=$(sed -n "/$keyword/ { s/$keyword//p; q; }" "${AbsolutePathToConfigArray[i]}") PROCESS_ROLE=$(sed -n "/$keyword/ { s/$keyword//p; q; }" "$AbsolutePathToConfig")
fi fi
if [ -n "$INPUT_PROCESS_ROLE" ] && [ "$PROCESS_ROLE" == "$INPUT_PROCESS_ROLE" ] || [ -n "$INPUT_NID" ] && [ "$NID" == "$INPUT_NID" ]; then if [ -n "$INPUT_PROCESS_ROLE" ] && [ "$PROCESS_ROLE" == "$INPUT_PROCESS_ROLE" ] || [ -n "$INPUT_NID" ] && [ "$NID" == "$INPUT_NID" ]; then
kill -s $SIGNAL ${PIDSArray[i]} kill -s $SIGNAL ${PIDSArray[i]}