Merge pull request #56513 from rosinL/wip-fix-65175
[ceph.git] / src / mstop.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 script_root=`dirname $0`
6
7 [ -z "$BUILD_DIR" ] && BUILD_DIR=build
8
9 if [ -e CMakeCache.txt ]; then
10     script_root=$PWD
11 elif [ -e $script_root/../${BUILD_DIR}/CMakeCache.txt ]; then
12     script_root=`(cd $script_root/../${BUILD_DIR}; pwd)`
13 fi
14
15 [ "$#" -lt 1 ] && echo "usage: $0 <name> [entity [id]]" && exit 1
16
17 name=$1
18 entity=$2
19 id=$3
20
21 run_root=$script_root/run/$name
22 pidpath=$run_root/out
23
24 if [ "$entity" == "" ]; then
25   pfiles=`ls $pidpath/*.pid` || true
26 elif [ "$id" == "" ]; then
27   pfiles=`ls $pidpath/$entity.*.pid` || true
28 else
29   pfiles=`ls $pidpath/$entity.$id.pid` || true
30 fi
31
32 MAX_RETRIES=20
33
34 for pidfile in $pfiles; do
35   pid=`cat $pidfile`
36   fname=`echo $pidfile | sed 's/.*\///g'`
37   [ "$pid" == "" ] && exit
38   [ $pid -eq 0 ] && exit
39   echo pid=$pid
40   extra_check=""
41   entity=`echo $fname | sed 's/\..*//g'`
42   name=`echo $fname | sed 's/\.pid$//g'`
43   [ "$entity" == "radosgw" ] && extra_check="-e lt-radosgw"
44   echo entity=$entity pid=$pid name=$name
45   counter=0
46   signal=""
47   while ps -p $pid -o args= | grep -q -e $entity $extracheck ; do
48     if [[ "$counter" -gt MAX_RETRIES ]]; then
49         signal="-9"
50     fi
51     cmd="kill $signal $pid"
52     printf "$cmd...\n"
53     $cmd
54     sleep 1
55     counter=$((counter+1))
56     continue
57   done
58 done
59