12a457
From ef1bf9e3bdddeef9019405a3c734731f221e99a2 Mon Sep 17 00:00:00 2001
12a457
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
12a457
Date: Tue, 10 May 2016 12:59:56 +0530
12a457
Subject: [PATCH 167/167] extras: stop all include glusterfs process as well
12a457
12a457
currently, extras/stop-all-gluster-processes.sh script handles
12a457
brick processes, node services and geo-rep's gsync process.
12a457
12a457
from now this script also handles mount processes as well,
12a457
as part of this patch I have reorganized this script
12a457
12a457
Backport of:
12a457
> Backport of:
12a457
>> Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0
12a457
>> BUG: 1334620
12a457
>> Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
12a457
>> Reviewed-on: http://review.gluster.org/14277
12a457
>> Tested-by: Prasanna Kumar Kalever <pkalever@redhat.com>
12a457
>> Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
>> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
>> Reviewed-by: Niels de Vos <ndevos@redhat.com>
12a457
>> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
>
12a457
> Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0
12a457
> BUG: 1334750
12a457
> Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
12a457
> Reviewed-on: http://review.gluster.org/14320
12a457
> Tested-by: Prasanna Kumar Kalever <pkalever@redhat.com>
12a457
> Smoke: Gluster Build System <jenkins@build.gluster.com>
12a457
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
12a457
> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
12a457
> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
12a457
12a457
Change-Id: I124aef632191a7ad7eb9ce53ea33c0d3c8ec7c8a
12a457
BUG: 1336332
12a457
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/74769
12a457
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
12a457
---
12a457
 extras/stop-all-gluster-processes.sh |   95 ++++++++++++++++++++++++----------
12a457
 1 files changed, 68 insertions(+), 27 deletions(-)
12a457
12a457
diff --git a/extras/stop-all-gluster-processes.sh b/extras/stop-all-gluster-processes.sh
12a457
index 25dc0ba..5bc58b3 100755
12a457
--- a/extras/stop-all-gluster-processes.sh
12a457
+++ b/extras/stop-all-gluster-processes.sh
12a457
@@ -1,43 +1,84 @@
12a457
-#! /bin/sh
12a457
+#!/usr/bin/env bash
12a457
 
12a457
-function main()
12a457
+# global
12a457
+errors=0
12a457
+
12a457
+# find the mounts and return their pids
12a457
+function get_mount_pids()
12a457
 {
12a457
-    errors=0;
12a457
+    local opts
12a457
+    local pid
12a457
 
12a457
-    for pidfile in $(find /var/lib/glusterd/ -iname '*pid');
12a457
+    for opts in $(grep -w fuse.glusterfs /proc/mounts| awk '{print $1":/"$2}');
12a457
     do
12a457
-        pid=$(cat ${pidfile});
12a457
-        echo "sending SIGTERM to process $pid";
12a457
-        kill -TERM $pid;
12a457
+        IFS=' ' read -r -a volinfo <<< $(echo "${opts}" | sed 's/:\// /g')
12a457
+        pid+="$(ps -Ao pid,args | grep -w "volfile-server=${volinfo[0]}" |
12a457
+                grep -w "volfile-id=/${volinfo[1]}" | grep -w "${volinfo[2]}" |
12a457
+                awk '{print $1}') "
12a457
     done
12a457
+    echo "${pid}"
12a457
+}
12a457
 
12a457
-    # for geo-replication, only 'monitor' has pid file written, other
12a457
-    # processes are not having a pid file, so get it through 'ps' and
12a457
-    # handle these processes
12a457
-    gsyncpid=`ps aux | grep gluster | grep gsync | awk '{print $2}'`;
12a457
-    if [ -n "$gsyncpid" ]
12a457
-    then
12a457
-        kill -TERM $gsyncpid || errors=$(($errors + 1));
12a457
-    fi
12a457
+# handle mount processes i.e. 'glusterfs'
12a457
+function kill_mounts()
12a457
+{
12a457
+    local signal=${1}
12a457
+    local pid
12a457
 
12a457
-    sleep 5;
12a457
+    for pid in $(get_mount_pids);
12a457
+    do
12a457
+        echo "sending SIG${signal} to mount process with pid: ${pid}";
12a457
+        kill -${signal} ${pid};
12a457
+    done
12a457
+}
12a457
+
12a457
+# handle brick processes and node services
12a457
+function kill_bricks_and_services()
12a457
+{
12a457
+    local signal=${1}
12a457
+    local pidfile
12a457
+    local pid
12a457
 
12a457
-    # if pid file still exists, its something to KILL
12a457
-    for pidfile in $(find /var/lib/glusterd/ -iname '*pid');
12a457
+    for pidfile in $(find /var/lib/glusterd/ -name '*.pid');
12a457
     do
12a457
-        pid=$(cat ${pidfile});
12a457
-        echo "sending SIGKILL to process $pid";
12a457
-        kill -KILL $pid;
12a457
+        local pid=$(cat ${pidfile});
12a457
+        echo "sending SIG${signal} to pid: ${pid}";
12a457
+        kill -${signal} ${pid};
12a457
     done
12a457
+}
12a457
+
12a457
+# for geo-replication, only 'monitor' has pid file written, other
12a457
+# processes are not having a pid file, so get it through 'ps' and
12a457
+# handle these processes
12a457
+function kill_georep_gsync()
12a457
+{
12a457
+    local signal=${1}
12a457
 
12a457
-    # handle 'KILL' of geo-replication
12a457
-    gsyncpid=`ps aux | grep gluster | grep gsync | awk '{print $2}'`;
12a457
-    if [ -n "$gsyncpid" ]
12a457
+    # FIXME: add strick/better check
12a457
+    local gsyncpid=$(ps -Ao pid,args | grep gluster | grep gsync |
12a457
+                     awk '{print $1}');
12a457
+    if [ -n "${gsyncpid}" ]
12a457
     then
12a457
-        kill -KILL $gsyncpid || errors=$(($errors + 1));
12a457
+        echo "sending SIG${signal} to geo-rep gsync process ${gsyncpid}";
12a457
+        kill -${signal} ${gsyncpid} || errors=$((${errors} + 1));
12a457
     fi
12a457
+}
12a457
+
12a457
+function main()
12a457
+{
12a457
+    kill_mounts TERM
12a457
+    kill_bricks_and_services TERM
12a457
+    kill_georep_gsync TERM
12a457
+
12a457
+    sleep 5;
12a457
+    echo ""
12a457
+
12a457
+    # still not Terminated? let's pass SIGKILL
12a457
+    kill_mounts KILL
12a457
+    kill_bricks_and_services KILL
12a457
+    kill_georep_gsync KILL
12a457
 
12a457
-    exit $errors;
12a457
+    exit ${errors};
12a457
 }
12a457
 
12a457
-main "$@";
12a457
+main
12a457
-- 
12a457
1.7.1
12a457