This is an automated email from the ASF dual-hosted git repository.
yong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 034e8997ab bookkeeper-daemon script supports restart command (#3649)
034e8997ab is described below
commit 034e8997ab43850d2968d8780abf9bb6e57dabd5
Author: gaozhangmin <[email protected]>
AuthorDate: Mon Nov 21 15:47:17 2022 +0800
bookkeeper-daemon script supports restart command (#3649)
### Motivation
bookkeeper-daemon script supports restart command
---
bin/bookkeeper-daemon.sh | 140 ++++++++++++++++++++++++++++-------------------
1 file changed, 83 insertions(+), 57 deletions(-)
diff --git a/bin/bookkeeper-daemon.sh b/bin/bookkeeper-daemon.sh
index 621aa18e6a..7e93b86334 100755
--- a/bin/bookkeeper-daemon.sh
+++ b/bin/bookkeeper-daemon.sh
@@ -108,75 +108,101 @@ rotate_out_log ()
mkdir -p "$BOOKIE_LOG_DIR"
-case $startStop in
- (start)
- if [ -f $pid_file ]; then
- PREVIOUS_PID=$(cat $pid_file)
- if kill -0 $PREVIOUS_PID > /dev/null 2>&1; then
- echo $command running as process $PREVIOUS_PID. Stop it first.
- exit 1
- fi
- fi
-
- rotate_out_log $out
- echo starting $command, logging to $logfile
- bookkeeper=$BK_HOME/bin/bookkeeper
- nohup $bookkeeper $command "$@" > "$out" 2>&1 < /dev/null &
- echo $! > $pid_file
- sleep 1; head $out
- sleep 2;
- if ! kill -0 $! > /dev/null ; then
+start()
+{
+ if [ -f $pid_file ]; then
+ PREVIOUS_PID=$(cat $pid_file)
+ if kill -0 $PREVIOUS_PID > /dev/null 2>&1; then
+ echo $command running as process $PREVIOUS_PID. Stop it first.
exit 1
fi
- ;;
+ fi
- (stop)
- if [ -f $pid_file ]; then
- TARGET_PID=$(cat $pid_file)
- if kill -0 $TARGET_PID > /dev/null 2>&1; then
- echo stopping $command
- kill $TARGET_PID
-
- count=0
- location=$BOOKIE_LOG_DIR
- while kill -0 $TARGET_PID > /dev/null 2>&1;
- do
- echo "Shutdown is in progress... Please wait..."
- sleep 1
- count=$(expr $count + 1)
-
- if [ "$count" = "$BOOKIE_STOP_TIMEOUT" ]; then
- break
- fi
- done
-
- if [ "$count" != "$BOOKIE_STOP_TIMEOUT" ]; then
- echo "Shutdown completed."
+ rotate_out_log $out
+ echo starting $command, logging to $logfile
+ bookkeeper=$BK_HOME/bin/bookkeeper
+ nohup $bookkeeper $command "$@" > "$out" 2>&1 < /dev/null &
+ echo $! > $pid_file
+ sleep 1; head $out
+ sleep 2;
+ if ! kill -0 $! > /dev/null ; then
+ exit 1
+ fi
+}
+
+stop()
+{
+ if [ -f $pid_file ]; then
+ TARGET_PID=$(cat $pid_file)
+ if kill -0 $TARGET_PID > /dev/null 2>&1; then
+ echo stopping $command
+ kill $TARGET_PID
+
+ count=0
+ location=$BOOKIE_LOG_DIR
+ while kill -0 $TARGET_PID > /dev/null 2>&1;
+ do
+ echo "Shutdown is in progress... Please wait..."
+ sleep 1
+ count=$(expr $count + 1)
+
+ if [ "$count" = "$BOOKIE_STOP_TIMEOUT" ]; then
+ break
fi
+ done
- 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 : Bookie Server is not stopped completely."
- exit 1
- fi
+ if [ "$count" != "$BOOKIE_STOP_TIMEOUT" ]; then
+ echo "Shutdown completed."
+ fi
+
+ 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 : Bookie Server is not stopped completely."
+ exit 1
fi
- else
- echo no $command to stop
fi
- rm $pid_file
else
echo no $command to stop
fi
+ rm $pid_file
+ else
+ echo no $command to stop
+ fi
+}
+case $startStop in
+ (start)
+ start "$*"
;;
+ (stop)
+ stop $1
+ ;;
+ (restart)
+ forceStopFlag=$(echo "$*"|grep "\-force")
+ if [[ "$forceStopFlag" != "" ]]
+ then
+ stop "-force"
+ else
+ stop
+ fi
+ if [ "$?" == 0 ]
+ then
+ sleep 3
+ paramaters="$*"
+ startParamaters=${paramaters//-force/}
+ start "$startParamaters"
+ else
+ echo "WARNNING : $command failed restart, for $command is not stopped
completely."
+ fi
+ ;;
(*)
usage
echo $supportedargs