This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 7273ffe  feat(cli): add restart command to pulsar-daemon (#12279)
7273ffe is described below

commit 7273ffe0860c25c9ede36a136ca377779a6eed89
Author: Eric Shen <[email protected]>
AuthorDate: Tue Oct 12 21:49:48 2021 -0500

    feat(cli): add restart command to pulsar-daemon (#12279)
    
    ### Motivation
    
    It's inconvenient to restart the broker/bk/zk process when users change the 
config, they have use `pulsar-daemon` stop the process first then start it 
again.
    
    ### Modifications
    
    I added a command as `restart` in `pulsar-daemon`.
    
    Signed-off-by: Eric Shen <[email protected]>
---
 bin/pulsar-daemon | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/bin/pulsar-daemon b/bin/pulsar-daemon
index 5b54e3b..f018bc4 100755
--- a/bin/pulsar-daemon
+++ b/bin/pulsar-daemon
@@ -20,7 +20,7 @@
 
 usage() {
     cat <<EOF
-Usage: pulsar-daemon (start|stop) <command> <args...>
+Usage: pulsar-daemon (start|stop|restart) <command> <args...>
 where command is one of:
     broker              Run a broker server
     bookie              Run a bookie server
@@ -205,6 +205,66 @@ case $startStop in
     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`
+
+          if [ "$count" = "$PULSAR_STOP_TIMEOUT" ]; then
+                break
+          fi
+         done
+
+        if [ "$count" != "$PULSAR_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 :  $command is not stopped completely."
+                 exit 1
+              fi
+        fi
+      else
+        echo "no $command to stop"
+      fi
+      rm $pid
+    else
+      echo no "$command to 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
+    fi
+    ;;
+
   (*)
     usage
     exit 1

Reply via email to