]>
Commit | Line | Data |
---|---|---|
9f95a23c | 1 | #!/usr/bin/env bash |
7c673cae FG |
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 | |
7c673cae FG |
22 | [ -z "$CEPH_BIN" ] && CEPH_BIN=bin |
23 | fi | |
24 | ||
11fdf7f2 TL |
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" | |
f6b5b4d7 | 31 | CEPHADM_DIR_PATH="$CEPH_CONF_PATH/../src/cephadm" |
11fdf7f2 | 32 | |
7c673cae FG |
33 | MYUID=$(id -u) |
34 | MYNAME=$(id -nu) | |
35 | ||
36 | do_killall() { | |
9f95a23c TL |
37 | local pname="ceph-run.*$1" |
38 | if [ $1 == "ganesha.nfsd" ]; then | |
39 | pname=$1 | |
40 | fi | |
41 | pg=`pgrep -u $MYUID -f $pname` | |
7c673cae FG |
42 | [ -n "$pg" ] && kill $pg |
43 | $SUDO killall -u $MYNAME $1 | |
44 | } | |
45 | ||
f6b5b4d7 TL |
46 | do_killcephadm() { |
47 | FSID=$($CEPH_BIN/ceph -c $conf_fn fsid) | |
48 | sudo $CEPHADM_DIR_PATH/cephadm rm-cluster --fsid $FSID --force | |
49 | } | |
50 | ||
9f95a23c TL |
51 | do_umountall() { |
52 | #VSTART_IP_PORTS is of the format as below | |
53 | #"[v[num]:IP:PORT/0,v[num]:IP:PORT/0][v[num]:IP:PORT/0,v[num]:IP:PORT/0]..." | |
54 | VSTART_IP_PORTS=$("${CEPH_BIN}"/ceph -c $conf_fn mon metadata 2>/dev/null | jq -j '.[].addrs') | |
55 | ||
56 | #SRC_MNT_ARRAY is of the format as below | |
57 | #SRC_MNT_ARRAY[0] = IP:PORT,IP:PORT,IP:PORT:/ | |
58 | #SRC_MNT_ARRAY[1] = MNT_POINT1 | |
59 | #SRC_MNT_ARRAY[2] = IP:PORT:/ #Could be mounted using single mon IP | |
60 | #SRC_MNT_ARRAY[3] = MNT_POINT2 | |
61 | #... | |
62 | SRC_MNT_ARRAY=($(findmnt -t ceph -n --raw --output=source,target)) | |
63 | LEN_SRC_MNT_ARRAY=${#SRC_MNT_ARRAY[@]} | |
64 | ||
65 | for (( i=0; i<${LEN_SRC_MNT_ARRAY}; i=$((i+2)) )) | |
66 | do | |
67 | # The first IP:PORT among the list is checked against vstart monitor IP:PORTS | |
68 | IP_PORT1=$(echo ${SRC_MNT_ARRAY[$i]} | awk -F ':/' '{print $1}' | awk -F ',' '{print $1}') | |
69 | if [[ "$VSTART_IP_PORTS" == *"$IP_PORT1"* ]] | |
70 | then | |
71 | CEPH_MNT=${SRC_MNT_ARRAY[$((i+1))]} | |
72 | [ -n "$CEPH_MNT" ] && sudo umount -f $CEPH_MNT | |
73 | fi | |
74 | done | |
75 | ||
76 | #Get fuse mounts of the cluster | |
77 | CEPH_FUSE_MNTS=$("${CEPH_BIN}"/ceph -c $conf_fn tell mds.* client ls 2>/dev/null | grep mount_point | tr -d '",' | awk '{print $2}') | |
78 | [ -n "$CEPH_FUSE_MNTS" ] && sudo umount -f $CEPH_FUSE_MNTS | |
79 | } | |
80 | ||
f6b5b4d7 | 81 | usage="usage: $0 [all] [mon] [mds] [osd] [rgw] [nfs] [--crimson] [--cephadm]\n" |
7c673cae FG |
82 | |
83 | stop_all=1 | |
84 | stop_mon=0 | |
85 | stop_mds=0 | |
86 | stop_osd=0 | |
87 | stop_mgr=0 | |
88 | stop_rgw=0 | |
9f95a23c TL |
89 | stop_ganesha=0 |
90 | ceph_osd=ceph-osd | |
f6b5b4d7 | 91 | stop_cephadm=0 |
7c673cae FG |
92 | |
93 | while [ $# -ge 1 ]; do | |
94 | case $1 in | |
95 | all ) | |
96 | stop_all=1 | |
97 | ;; | |
98 | mon | ceph-mon ) | |
99 | stop_mon=1 | |
100 | stop_all=0 | |
101 | ;; | |
102 | mgr | ceph-mgr ) | |
103 | stop_mgr=1 | |
104 | stop_all=0 | |
105 | ;; | |
106 | mds | ceph-mds ) | |
107 | stop_mds=1 | |
108 | stop_all=0 | |
109 | ;; | |
110 | osd | ceph-osd ) | |
111 | stop_osd=1 | |
112 | stop_all=0 | |
113 | ;; | |
114 | rgw | ceph-rgw ) | |
115 | stop_rgw=1 | |
116 | stop_all=0 | |
117 | ;; | |
f6b5b4d7 | 118 | nfs | ganesha.nfsd ) |
9f95a23c TL |
119 | stop_ganesha=1 |
120 | stop_all=0 | |
121 | ;; | |
122 | --crimson) | |
123 | ceph_osd=crimson-osd | |
124 | ;; | |
f6b5b4d7 TL |
125 | --cephadm) |
126 | stop_cephadm=1 | |
127 | stop_all=0 | |
128 | ;; | |
7c673cae FG |
129 | * ) |
130 | printf "$usage" | |
131 | exit | |
132 | esac | |
133 | shift | |
134 | done | |
135 | ||
136 | if [ $stop_all -eq 1 ]; then | |
9f95a23c TL |
137 | if "${CEPH_BIN}"/ceph -s --connect-timeout 1 -c $conf_fn >/dev/null 2>&1; then |
138 | # Umount mounted filesystems from vstart cluster | |
139 | do_umountall | |
140 | fi | |
141 | ||
11fdf7f2 TL |
142 | if "${CEPH_BIN}"/rbd device list -c $conf_fn >/dev/null 2>&1; then |
143 | "${CEPH_BIN}"/rbd device list -c $conf_fn | tail -n +2 | | |
7c673cae FG |
144 | while read DEV; do |
145 | # While it is currently possible to create an rbd image with | |
146 | # whitespace chars in its name, krbd will refuse mapping such | |
147 | # an image, so we can safely split on whitespace here. (The | |
148 | # same goes for whitespace chars in names of the pools that | |
149 | # contain rbd images). | |
150 | DEV="$(echo "${DEV}" | tr -s '[:space:]' | awk '{ print $5 }')" | |
11fdf7f2 | 151 | sudo "${CEPH_BIN}"/rbd device unmap "${DEV}" -c $conf_fn |
7c673cae FG |
152 | done |
153 | ||
11fdf7f2 | 154 | if [ -n "$("${CEPH_BIN}"/rbd device list -c $conf_fn)" ]; then |
7c673cae FG |
155 | echo "WARNING: Some rbd images are still mapped!" >&2 |
156 | fi | |
157 | fi | |
158 | ||
f6b5b4d7 TL |
159 | daemons="$($CEPHADM_DIR_PATH/cephadm ls 2> /dev/null)" |
160 | if [ $? -eq 0 -a "$daemons" != "[]" ]; then | |
161 | do_killcephadm | |
162 | fi | |
163 | ||
f67539c2 | 164 | for p in $ceph_osd ceph-mon ceph-mds ceph-mgr radosgw lt-radosgw apache2 ganesha.nfsd ; do |
7c673cae FG |
165 | for try in 0 1 1 1 1 ; do |
166 | if ! pkill -u $MYUID $p ; then | |
167 | break | |
168 | fi | |
169 | sleep $try | |
170 | done | |
171 | done | |
172 | ||
173 | pkill -u $MYUID -f valgrind.bin.\*ceph-mon | |
9f95a23c | 174 | $SUDO pkill -u $MYUID -f valgrind.bin.\*$ceph_osd |
7c673cae | 175 | pkill -u $MYUID -f valgrind.bin.\*ceph-mds |
11fdf7f2 | 176 | asok_dir=`dirname $("${CEPH_BIN}"/ceph-conf -c ${conf_fn} --show-config-value admin_socket)` |
c07f9fc5 | 177 | rm -rf "${asok_dir}" |
7c673cae FG |
178 | else |
179 | [ $stop_mon -eq 1 ] && do_killall ceph-mon | |
180 | [ $stop_mds -eq 1 ] && do_killall ceph-mds | |
9f95a23c | 181 | [ $stop_osd -eq 1 ] && do_killall $ceph_osd |
7c673cae | 182 | [ $stop_mgr -eq 1 ] && do_killall ceph-mgr |
9f95a23c | 183 | [ $stop_ganesha -eq 1 ] && do_killall ganesha.nfsd |
7c673cae | 184 | [ $stop_rgw -eq 1 ] && do_killall radosgw lt-radosgw apache2 |
f6b5b4d7 | 185 | [ $stop_cephadm -eq 1 ] && do_killcephadm |
7c673cae | 186 | fi |