]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
stop.sh: restructure stop logic
authorKefu Chai <kchai@redhat.com>
Thu, 1 Apr 2021 09:53:00 +0000 (17:53 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 1 Apr 2021 10:59:50 +0000 (18:59 +0800)
avoid using multiple loops for stopping daemons, and to move the
related logic to a single place for better readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/stop.sh

index 07f04f4a4e4ec176c30a706182d4bc4a38478803..659dcfcdae37bf5bb30ca3fcb796cec69691ffc0 100755 (executable)
@@ -165,33 +165,40 @@ if [ $stop_all -eq 1 ]; then
 
     # killing processes
     to_kill="$ceph_osd ceph-mon ceph-mds ceph-mgr radosgw lt-radosgw apache2 ganesha.nfsd"
-    for p in $to_kill ; do
-        if pkill -u $MYUID $p; then
-           still_runs="$still_runs $p"
-       fi
-    done
-
-    # wait for processes to close
-    for try in 1 1 2 3 5 8 ; do
-        to_kill="$still_runs"
-       still_runs=""
-        for p in $to_kill ; do
-            if pkill -u $MYUID $p -0; then
-               still_runs="$still_runs $p"
-            fi
+    since_kill=0
+    for step in 0 1 1 2 3 5 8; do
+        sleep $step
+        since_kill=$((since_kill + step))
+        survivors=''
+        for p in $to_kill; do
+            case $step in
+                0)
+                    # killing processes
+                    pkill -SIGTERM -u $MYUID $p
+                    ;;
+                [1-5])
+                    # wait for processes to stop
+                    if pkill -0 -u $MYUID $p; then
+                        # $p is still alive
+                        survivors+=" $p"
+                    fi
+                    ;;
+                8)
+                    # kill and print if some left
+                    if pkill -0 -u $MYUID $p; then
+                       pkill -SIGKILL -u $MYUID $p
+                       echo "WARNING: $p did not orderly shutdown, killing it hard!" >&2
+                    fi
+                    ;;
+            esac
         done
-        if [ -z "$still_runs" ] ; then
+        if [ $since_kill -eq 0 ]; then
+            continue
+        elif [ -z "$survivors" ]; then
             break
         fi
-        sleep $try
-    done
-
-    # kill and print if some left
-    for p in $still_runs ; do
-        if pkill -u $MYUID $p -0; then
-            echo "TIMEOUT! $p did not orderly shutdown, killing it hard"
-            pkill -u $MYUID $p -SIGKILL
-        fi
+        to_kill=$survivors
+        echo "WARNING: $to_kill still alive after $since_kill seconds" >&2
     done
 
     pkill -u $MYUID -f valgrind.bin.\*ceph-mon