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

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


The following commit(s) were added to refs/heads/master by this push:
     new e210db426c [opt] stop script opt (#11183)
e210db426c is described below

commit e210db426ccb176397f7da55021d9969fac209e0
Author: Dongyang Li <hello_step...@qq.com>
AuthorDate: Wed Jul 27 11:32:26 2022 +0800

    [opt] stop script opt (#11183)
---
 be/src/service/doris_main.cpp |  3 +-
 bin/stop_be.sh                | 61 +++++++++++++++++++++++------------
 bin/stop_fe.sh                | 75 ++++++++++++++++++++++++++++++++-----------
 3 files changed, 98 insertions(+), 41 deletions(-)

diff --git a/be/src/service/doris_main.cpp b/be/src/service/doris_main.cpp
index 68cff8e08a..c68add8a76 100644
--- a/be/src/service/doris_main.cpp
+++ b/be/src/service/doris_main.cpp
@@ -281,7 +281,8 @@ int main(int argc, char** argv) {
 
     // open pid file, obtain file lock and save pid
     string pid_file = string(getenv("PID_DIR")) + "/be.pid";
-    int fd = open(pid_file.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | 
S_IRGRP | S_IWGRP);
+    int fd = open(pid_file.c_str(), O_RDWR | O_CREAT,
+                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
     if (fd < 0) {
         fprintf(stderr, "fail to create pid file.");
         exit(-1);
diff --git a/bin/stop_be.sh b/bin/stop_be.sh
index 0ce5124934..1ea07d8b2e 100755
--- a/bin/stop_be.sh
+++ b/bin/stop_be.sh
@@ -16,11 +16,20 @@
 # specific language governing permissions and limitations
 # under the License.
 
-curdir=`dirname "$0"`
-curdir=`cd "$curdir"; pwd`
+curdir=$(dirname "$0")
+curdir=$(
+    cd "$curdir"
+    pwd
+)
 
-export DORIS_HOME=`cd "$curdir/.."; pwd`
-export PID_DIR=`cd "$curdir"; pwd`
+export DORIS_HOME=$(
+    cd "$curdir/.."
+    pwd
+)
+export PID_DIR=$(
+    cd "$curdir"
+    pwd
+)
 
 signum=9
 if [ "x"$1 = "x--grace" ]; then
@@ -28,37 +37,47 @@ if [ "x"$1 = "x--grace" ]; then
 fi
 
 while read line; do
-    envline=`echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 
's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*="`
-    envline=`eval "echo $envline"`
+    envline=$(echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 
's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=")
+    envline=$(eval "echo $envline")
     if [[ $envline == *"="* ]]; then
         eval 'export "$envline"'
     fi
-done < $DORIS_HOME/conf/be.conf
+done <$DORIS_HOME/conf/be.conf
 
 pidfile=$PID_DIR/be.pid
 
 if [ -f $pidfile ]; then
-    pid=`cat $pidfile`
-    pidcomm=`ps -p $pid -o comm=`
+    pid=$(cat $pidfile)
+
+    #check if pid valid
+    if test -z "$pid"; then
+        echo "ERROR: invalid pid."
+        exit 1
+    fi
+
+    #check if pid process exist
+    if ! kill -0 $pid; then
+        echo "ERROR: be process $pid does not exist."
+        exit 1
+    fi
+
+    pidcomm=$(ps -p $pid -o comm=)
+    #check if pid process is backend process
     if [ "doris_be"x != "$pidcomm"x ]; then
         echo "ERROR: pid process may not be be. "
         exit 1
     fi
 
-    if kill -0 $pid; then
-        if kill -${signum} $pid > /dev/null 2>&1; then
-            echo "stop $pidcomm, and remove pid file. "
-            rm $pidfile
-            exit 0
-        else
-            exit 1
-        fi
-    else
-        echo "Backend already exit, remove pid file. "
+    # kill
+    if kill -${signum} $pid >/dev/null 2>&1; then
+        echo "stop $pidcomm, and remove pid file. "
         rm $pidfile
+        exit 0
+    else
+        echo "ERROR: failed to stop $pid"
+        exit 1
     fi
 else
-    echo "$pidfile does not exist"
+    echo "ERROR: $pidfile does not exist"
     exit 1
 fi
-
diff --git a/bin/stop_fe.sh b/bin/stop_fe.sh
index 0c0a357310..4910387111 100755
--- a/bin/stop_fe.sh
+++ b/bin/stop_fe.sh
@@ -16,33 +16,70 @@
 # specific language governing permissions and limitations
 # under the License.
 
-curdir=`dirname "$0"`
-curdir=`cd "$curdir"; pwd`
+curdir=$(dirname "$0")
+curdir=$(
+    cd "$curdir"
+    pwd
+)
 
-export DORIS_HOME=`cd "$curdir/.."; pwd`
-export PID_DIR=`cd "$curdir"; pwd`
+export DORIS_HOME=$(
+    cd "$curdir/.."
+    pwd
+)
+export PID_DIR=$(
+    cd "$curdir"
+    pwd
+)
 
 while read line; do
-    envline=`echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 
's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*="`
-    envline=`eval "echo $envline"`
+    envline=$(echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 
's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=")
+    envline=$(eval "echo $envline")
     if [[ $envline == *"="* ]]; then
         eval 'export "$envline"'
     fi
-done < $DORIS_HOME/conf/fe.conf
+done <$DORIS_HOME/conf/fe.conf
 
 pidfile=$PID_DIR/fe.pid
 
 if [ -f $pidfile ]; then
-   pid=`cat $pidfile`
-   pidcomm=`ps -p $pid -o comm=`
-   
-   if [ "java" != "$pidcomm" ]; then
-       echo "ERROR: pid process may not be fe. "
-   fi
-
-   if kill -9 $pid > /dev/null 2>&1; then
-        echo "stop $pidcomm, and remove pid file. "
-        rm $pidfile
-   fi
-fi
+    pid=$(cat $pidfile)
+
+    #check if pid valid
+    if test -z "$pid"; then
+        echo "ERROR: invalid pid."
+        exit 1
+    fi
+
+    #check if pid process exist
+    if ! kill -0 $pid; then
+        echo "ERROR: fe process $pid does not exist."
+        exit 1
+    fi
 
+    pidcomm=$(ps -p $pid -o comm=)
+    #check if pid process is frontend process
+    if [ "java"x != "$pidcomm"x ]; then
+        echo "ERROR: pid process may not be fe. "
+        exit 1
+    fi
+
+    #kill pid process and check it
+    if kill $pid >/dev/null 2>&1; then
+        while true; do
+            if ps -p $pid >/dev/null; then
+                echo "waiting fe to stop, pid: $pid"
+                sleep 2
+            else
+                echo "stop $pidcomm, and remove pid file. "
+                if [ -f $pidfile ]; then rm $pidfile; fi
+                exit 0
+            fi
+        done
+    else
+        echo "ERROR: failed to stop $pid"
+        exit 1
+    fi
+else
+    echo "ERROR: $pidfile does not exist"
+    exit 1
+fi


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to