]> git.proxmox.com Git - ceph.git/blob - ceph/src/stop.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / stop.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2013 Inktank <info@inktank.com>
4 # Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
5 #
6 # Author: Loic Dachary <loic@dachary.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library Public License for more details.
17 #
18
19 test -d dev/osd0/. && test -e dev/sudo && SUDO="sudo"
20
21 if [ -e CMakeCache.txt ]; then
22 [ -z "$CEPH_BIN" ] && CEPH_BIN=bin
23 fi
24
25 if [ -n "$VSTART_DEST" ]; then
26 CEPH_CONF_PATH=$VSTART_DEST
27 else
28 CEPH_CONF_PATH="$PWD"
29 fi
30 conf_fn="$CEPH_CONF_PATH/ceph.conf"
31
32 MYUID=$(id -u)
33 MYNAME=$(id -nu)
34
35 do_killall() {
36 local pname="ceph-run.*$1"
37 if [ $1 == "ganesha.nfsd" ]; then
38 pname=$1
39 fi
40 pg=`pgrep -u $MYUID -f $pname`
41 [ -n "$pg" ] && kill $pg
42 $SUDO killall -u $MYNAME $1
43 }
44
45 do_umountall() {
46 #VSTART_IP_PORTS is of the format as below
47 #"[v[num]:IP:PORT/0,v[num]:IP:PORT/0][v[num]:IP:PORT/0,v[num]:IP:PORT/0]..."
48 VSTART_IP_PORTS=$("${CEPH_BIN}"/ceph -c $conf_fn mon metadata 2>/dev/null | jq -j '.[].addrs')
49
50 #SRC_MNT_ARRAY is of the format as below
51 #SRC_MNT_ARRAY[0] = IP:PORT,IP:PORT,IP:PORT:/
52 #SRC_MNT_ARRAY[1] = MNT_POINT1
53 #SRC_MNT_ARRAY[2] = IP:PORT:/ #Could be mounted using single mon IP
54 #SRC_MNT_ARRAY[3] = MNT_POINT2
55 #...
56 SRC_MNT_ARRAY=($(findmnt -t ceph -n --raw --output=source,target))
57 LEN_SRC_MNT_ARRAY=${#SRC_MNT_ARRAY[@]}
58
59 for (( i=0; i<${LEN_SRC_MNT_ARRAY}; i=$((i+2)) ))
60 do
61 # The first IP:PORT among the list is checked against vstart monitor IP:PORTS
62 IP_PORT1=$(echo ${SRC_MNT_ARRAY[$i]} | awk -F ':/' '{print $1}' | awk -F ',' '{print $1}')
63 if [[ "$VSTART_IP_PORTS" == *"$IP_PORT1"* ]]
64 then
65 CEPH_MNT=${SRC_MNT_ARRAY[$((i+1))]}
66 [ -n "$CEPH_MNT" ] && sudo umount -f $CEPH_MNT
67 fi
68 done
69
70 #Get fuse mounts of the cluster
71 CEPH_FUSE_MNTS=$("${CEPH_BIN}"/ceph -c $conf_fn tell mds.* client ls 2>/dev/null | grep mount_point | tr -d '",' | awk '{print $2}')
72 [ -n "$CEPH_FUSE_MNTS" ] && sudo umount -f $CEPH_FUSE_MNTS
73 }
74
75 usage="usage: $0 [all] [mon] [mds] [osd] [rgw] [ganesha] [--crimson]\n"
76
77 stop_all=1
78 stop_mon=0
79 stop_mds=0
80 stop_osd=0
81 stop_mgr=0
82 stop_rgw=0
83 stop_ganesha=0
84 ceph_osd=ceph-osd
85
86 while [ $# -ge 1 ]; do
87 case $1 in
88 all )
89 stop_all=1
90 ;;
91 mon | ceph-mon )
92 stop_mon=1
93 stop_all=0
94 ;;
95 mgr | ceph-mgr )
96 stop_mgr=1
97 stop_all=0
98 ;;
99 mds | ceph-mds )
100 stop_mds=1
101 stop_all=0
102 ;;
103 osd | ceph-osd )
104 stop_osd=1
105 stop_all=0
106 ;;
107 rgw | ceph-rgw )
108 stop_rgw=1
109 stop_all=0
110 ;;
111 ganesha | ganesha.nfsd )
112 stop_ganesha=1
113 stop_all=0
114 ;;
115 --crimson)
116 ceph_osd=crimson-osd
117 ;;
118 * )
119 printf "$usage"
120 exit
121 esac
122 shift
123 done
124
125 if [ $stop_all -eq 1 ]; then
126 if "${CEPH_BIN}"/ceph -s --connect-timeout 1 -c $conf_fn >/dev/null 2>&1; then
127 # Umount mounted filesystems from vstart cluster
128 do_umountall
129 fi
130
131 if "${CEPH_BIN}"/rbd device list -c $conf_fn >/dev/null 2>&1; then
132 "${CEPH_BIN}"/rbd device list -c $conf_fn | tail -n +2 |
133 while read DEV; do
134 # While it is currently possible to create an rbd image with
135 # whitespace chars in its name, krbd will refuse mapping such
136 # an image, so we can safely split on whitespace here. (The
137 # same goes for whitespace chars in names of the pools that
138 # contain rbd images).
139 DEV="$(echo "${DEV}" | tr -s '[:space:]' | awk '{ print $5 }')"
140 sudo "${CEPH_BIN}"/rbd device unmap "${DEV}" -c $conf_fn
141 done
142
143 if [ -n "$("${CEPH_BIN}"/rbd device list -c $conf_fn)" ]; then
144 echo "WARNING: Some rbd images are still mapped!" >&2
145 fi
146 fi
147
148 for p in ceph-mon ceph-mds $ceph_osd ceph-mgr radosgw lt-radosgw apache2 ganesha.nfsd ; do
149 for try in 0 1 1 1 1 ; do
150 if ! pkill -u $MYUID $p ; then
151 break
152 fi
153 sleep $try
154 done
155 done
156
157 pkill -u $MYUID -f valgrind.bin.\*ceph-mon
158 $SUDO pkill -u $MYUID -f valgrind.bin.\*$ceph_osd
159 pkill -u $MYUID -f valgrind.bin.\*ceph-mds
160 asok_dir=`dirname $("${CEPH_BIN}"/ceph-conf -c ${conf_fn} --show-config-value admin_socket)`
161 rm -rf "${asok_dir}"
162 else
163 [ $stop_mon -eq 1 ] && do_killall ceph-mon
164 [ $stop_mds -eq 1 ] && do_killall ceph-mds
165 [ $stop_osd -eq 1 ] && do_killall $ceph_osd
166 [ $stop_mgr -eq 1 ] && do_killall ceph-mgr
167 [ $stop_ganesha -eq 1 ] && do_killall ganesha.nfsd
168 [ $stop_rgw -eq 1 ] && do_killall radosgw lt-radosgw apache2
169 fi