Skip to content

Commit

Permalink
[apache#12279 ] missed check exit code of stop before calling start (a…
Browse files Browse the repository at this point in the history
…pache#12368)

apache#12279  missed check exit code of stop before calling start method, avoiding stop failed and continue to call start.

also apache#12279 has another problem, When restarting with `-force`, `-force` flag will also be passed to `start` by `$@`.
throws` Caused by: org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -force`
  • Loading branch information
gaozhangmin authored Nov 10, 2021
1 parent 0f9bcbc commit aa45ecd
Showing 1 changed file with 31 additions and 62 deletions.
93 changes: 31 additions & 62 deletions bin/pulsar-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ rotate_out_log ()
fi
}

mkdir -p "$PULSAR_LOG_DIR"

case $startStop in
(start)
if [ -f $pid ]; then
start ()
{
if [ -f $pid ]; then
if kill -0 `cat $pid` > /dev/null 2>&1; then
echo $command running as process `cat $pid`. Stop it first.
exit 1
Expand All @@ -149,17 +147,18 @@ case $startStop in
echo starting $command, logging to $logfile
echo Note: Set immediateFlush to true in conf/log4j2.yaml will guarantee the logging event is flushing to disk immediately. The default behavior is switched off due to performance considerations.
pulsar=$PULSAR_HOME/bin/pulsar
nohup $pulsar $command "$@" > "$out" 2>&1 < /dev/null &
nohup $pulsar $command "$1" > "$out" 2>&1 < /dev/null &
echo $! > $pid
sleep 1; head $out
sleep 2;
if ! ps -p $! > /dev/null ; then
exit 1
fi
;;
}

(stop)
if [ -f $pid ]; then
stop ()
{
if [ -f $pid ]; then
TARGET_PID=$(cat $pid)
if kill -0 $TARGET_PID > /dev/null 2>&1; then
echo "stopping $command"
Expand Down Expand Up @@ -203,65 +202,35 @@ case $startStop in
else
echo no "$command to stop"
fi
;;

(restart)
if [ -f $pid ]; then
TARGET_PID=$(cat $pid)
if kill -0 $TARGET_PID > /dev/null 2>&1; then
echo "stopping $command"
kill $TARGET_PID
}

count=0
location=$PULSAR_LOG_DIR
while ps -p $TARGET_PID > /dev/null;
do
echo "Shutdown is in progress... Please wait..."
sleep 1
count=`expr $count + 1`
mkdir -p "$PULSAR_LOG_DIR"

if [ "$count" = "$PULSAR_STOP_TIMEOUT" ]; then
break
fi
done
case $startStop in
(start)
start "$*"
;;

if [ "$count" != "$PULSAR_STOP_TIMEOUT" ]; then
echo "Shutdown completed."
fi
(stop)
stop $1
;;

if kill -0 $TARGET_PID > /dev/null 2>&1; then
fileName=$location/$command.out
$JAVA_HOME/bin/jstack $TARGET_PID > $fileName
echo "Thread dumps are taken for analysis at $fileName"
if [ "$1" == "-force" ]
then
echo "forcefully stopping $command"
kill -9 $TARGET_PID >/dev/null 2>&1
echo Successfully stopped the process
else
echo "WARNNING : $command is not stopped completely."
exit 1
fi
fi
else
echo "no $command to stop"
fi
rm $pid
(restart)
forceStopFlag=$(echo "$*"|grep "\-force")
if [[ "$forceStopFlag" != "" ]]
then
stop "-force"
else
echo no "$command to stop"
stop
fi
sleep 3

rotate_out_log $out
echo restarting $command, logging to $logfile
echo Note: Set immediateFlush to true in conf/log4j2.yaml will guarantee the logging event is flushing to disk immediately. The default behavior is switched off due to performance considerations.
pulsar=$PULSAR_HOME/bin/pulsar
nohup $pulsar $command "$@" > "$out" 2>&1 < /dev/null &
echo $! > $pid
sleep 1; head $out
sleep 2;
if ! ps -p $! > /dev/null ; then
exit 1
if [ "$?" == 0 ]
then
sleep 3
paramaters="$*"
startParamaters=${paramaters//-force/}
start "$startParamaters"
else
echo "WARNNING : $command failed restart, for $command is not stopped completely."
fi
;;

Expand Down

0 comments on commit aa45ecd

Please sign in to comment.