From 1ab8c44c56a13dc3fbc948bdfc1a3dfe80d66da9 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Tue, 10 May 2016 12:59:56 +0530 Subject: 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: > Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0 > BUG: 1334620 > Signed-off-by: Prasanna Kumar Kalever > Reviewed-on: http://review.gluster.org/14277 > Tested-by: Prasanna Kumar Kalever > Smoke: Gluster Build System > NetBSD-regression: NetBSD Build System > Reviewed-by: Niels de Vos > CentOS-regression: Gluster Build System Change-Id: Id62d6fda6dd331bde722ce3d99ec3f09fed55cb0 BUG: 1335726 Signed-off-by: Prasanna Kumar Kalever Reviewed-on: http://review.gluster.org/14321 Tested-by: Prasanna Kumar Kalever Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Kaleb KEITHLEY Reviewed-by: Niels de Vos --- extras/stop-all-gluster-processes.sh | 95 ++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/extras/stop-all-gluster-processes.sh b/extras/stop-all-gluster-processes.sh index 25dc0ba6bf6..5bc58b30f4e 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 -- cgit