Blob Blame History Raw
From ef1bf9e3bdddeef9019405a3c734731f221e99a2 Mon Sep 17 00:00:00 2001
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Date: Tue, 10 May 2016 12:59:56 +0530
Subject: [PATCH 167/167] extras: stop all include glusterfs process as well

currently, extras/stop-all-gluster-processes.sh script handles
brick processes, node services and geo-rep's gsync process.

from now this script also handles mount processes as well,
as part of this patch I have reorganized this script

Backport of:
> Backport of:
>> Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0
>> BUG: 1334620
>> Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
>> Reviewed-on: http://review.gluster.org/14277
>> Tested-by: Prasanna Kumar Kalever <pkalever@redhat.com>
>> Smoke: Gluster Build System <jenkins@build.gluster.com>
>> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>> Reviewed-by: Niels de Vos <ndevos@redhat.com>
>> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
>
> Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0
> BUG: 1334750
> Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
> Reviewed-on: http://review.gluster.org/14320
> Tested-by: Prasanna Kumar Kalever <pkalever@redhat.com>
> Smoke: Gluster Build System <jenkins@build.gluster.com>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>

Change-Id: I124aef632191a7ad7eb9ce53ea33c0d3c8ec7c8a
BUG: 1336332
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/74769
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
---
 extras/stop-all-gluster-processes.sh |   95 ++++++++++++++++++++++++----------
 1 files changed, 68 insertions(+), 27 deletions(-)

diff --git a/extras/stop-all-gluster-processes.sh b/extras/stop-all-gluster-processes.sh
index 25dc0ba..5bc58b3 100755
--- a/extras/stop-all-gluster-processes.sh
+++ b/extras/stop-all-gluster-processes.sh
@@ -1,43 +1,84 @@
-#! /bin/sh
+#!/usr/bin/env bash
 
-function main()
+# global
+errors=0
+
+# find the mounts and return their pids
+function get_mount_pids()
 {
-    errors=0;
+    local opts
+    local pid
 
-    for pidfile in $(find /var/lib/glusterd/ -iname '*pid');
+    for opts in $(grep -w fuse.glusterfs /proc/mounts| awk '{print $1":/"$2}');
     do
-        pid=$(cat ${pidfile});
-        echo "sending SIGTERM to process $pid";
-        kill -TERM $pid;
+        IFS=' ' read -r -a volinfo <<< $(echo "${opts}" | sed 's/:\// /g')
+        pid+="$(ps -Ao pid,args | grep -w "volfile-server=${volinfo[0]}" |
+                grep -w "volfile-id=/${volinfo[1]}" | grep -w "${volinfo[2]}" |
+                awk '{print $1}') "
     done
+    echo "${pid}"
+}
 
-    # for geo-replication, only 'monitor' has pid file written, other
-    # processes are not having a pid file, so get it through 'ps' and
-    # handle these processes
-    gsyncpid=`ps aux | grep gluster | grep gsync | awk '{print $2}'`;
-    if [ -n "$gsyncpid" ]
-    then
-        kill -TERM $gsyncpid || errors=$(($errors + 1));
-    fi
+# handle mount processes i.e. 'glusterfs'
+function kill_mounts()
+{
+    local signal=${1}
+    local pid
 
-    sleep 5;
+    for pid in $(get_mount_pids);
+    do
+        echo "sending SIG${signal} to mount process with pid: ${pid}";
+        kill -${signal} ${pid};
+    done
+}
+
+# handle brick processes and node services
+function kill_bricks_and_services()
+{
+    local signal=${1}
+    local pidfile
+    local pid
 
-    # if pid file still exists, its something to KILL
-    for pidfile in $(find /var/lib/glusterd/ -iname '*pid');
+    for pidfile in $(find /var/lib/glusterd/ -name '*.pid');
     do
-        pid=$(cat ${pidfile});
-        echo "sending SIGKILL to process $pid";
-        kill -KILL $pid;
+        local pid=$(cat ${pidfile});
+        echo "sending SIG${signal} to pid: ${pid}";
+        kill -${signal} ${pid};
     done
+}
+
+# for geo-replication, only 'monitor' has pid file written, other
+# processes are not having a pid file, so get it through 'ps' and
+# handle these processes
+function kill_georep_gsync()
+{
+    local signal=${1}
 
-    # handle 'KILL' of geo-replication
-    gsyncpid=`ps aux | grep gluster | grep gsync | awk '{print $2}'`;
-    if [ -n "$gsyncpid" ]
+    # FIXME: add strick/better check
+    local gsyncpid=$(ps -Ao pid,args | grep gluster | grep gsync |
+                     awk '{print $1}');
+    if [ -n "${gsyncpid}" ]
     then
-        kill -KILL $gsyncpid || errors=$(($errors + 1));
+        echo "sending SIG${signal} to geo-rep gsync process ${gsyncpid}";
+        kill -${signal} ${gsyncpid} || errors=$((${errors} + 1));
     fi
+}
+
+function main()
+{
+    kill_mounts TERM
+    kill_bricks_and_services TERM
+    kill_georep_gsync TERM
+
+    sleep 5;
+    echo ""
+
+    # still not Terminated? let's pass SIGKILL
+    kill_mounts KILL
+    kill_bricks_and_services KILL
+    kill_georep_gsync KILL
 
-    exit $errors;
+    exit ${errors};
 }
 
-main "$@";
+main
-- 
1.7.1