Debian Codegraph @

bin/ct-emptying-osd-server

raw symbols SCIP
1 #!/bin/bash
2 # Default Values
3 #set -x
4 source /usr/share/ceph-tools/_ct-common
5
6 help_msg () {
7 printf """
8 usage: $0 [-h] $CT_HELP_DESCR ...
9
10 Description Emptying an OSD server
11
12 Optional
13 $CT_HELP_MSG
14
15 Example
16 $0 $CT_HELP_EXAMPLE
17 """
18 }
19
20 osd_noexist(){
21 ret=$(ceph osd crush dump |jq '.devices[] | select(.id=='${1}')'|wc -l)
22 return $ret
23 }
24
25 check_balancer(){
26 # Test balancer status
27 [ "$(ceph balancer status | jq .active)" == "true" ]
28 }
29
30 check_flag(){
31 # Test flag
32 # Param 1: flag to test
33 [ "$(ceph -s | grep flags | grep ${1} | wc -l)" -eq "1" ]
34 }
35
36 check_osd_down(){
37 # Test if OSD down
38 # Param 1: osdid
39 [ "$(ceph osd tree -f json| jq '.nodes[]|select(.id=='${1}').status')" == "\"down\"" ]
40 }
41
42 check_osd_out(){
43 # Test if OSD out
44 # Param 1: osdid
45 [ "$(ceph osd tree -f json| jq '.nodes[]|select(.id=='${1}').reweight')" -eq "0" ]
46 }
47
48 check_osd_config(){
49 # Test if OSD config
50 # Param 1: key to test
51 # Param 2: value to test
52 [ "$(ct-osd-config -g ${1} 2>/dev/null | head -1 | awk '{print $3}')" == "\"${2}\"" ]
53 }
54
55 check_osd_purged(){
56 # Test if OSD out
57 # Param 1: osdid
58 HOST=$(hostname -s)
59 [ "$(ceph osd crush ls $HOST | grep -e"^osd.${1}$" |wc -l)" -eq "0" ]
60 }
61
62 check_osd_disabled(){
63 # Test if OSD service is disable
64 # Param 1: osdid
65 systemctl is-enabled ceph-osd@${1}.service 2>&1 >/dev/null
66 }
67
68 check_osd_zapped(){
69 # Test if OSD service is zapped
70 # Param 1: osdid
71 ! ceph-volume lvm list | grep " osd id"| grep $i
72 }
73
74 ct_help $@
75 shift $?
76 # Beginning of operations
77
78 ceph balancer off
79 while check_balancer; do sleep 1;done
80
81 ceph osd set noin
82 while ! check_flag "noin"; do sleep 1; done
83 ceph osd set noout
84 while ! check_flag "noout"; do sleep 1; done
85
86 OSDLIST=$(ceph osd tree-from $(hostname -s) | sed '1,2d' | awk '{print $1}')
87 for i in $OSDLIST ;do
88 ct_healthy_wait
89 echo "Set osd.${i} DOWN"
90 systemctl stop ceph-osd@${i}.service
91 while ! check_osd_down $i; do sleep 2; done
92 ceph osd out $i
93 while ! check_osd_out $i; do sleep 2; done
94 ct-upmap-remapped | sh 2> /dev/null
95 done
96
97
98 ct_healthy_wait
99 echo "Set balancer On"
100 ceph balancer on
101 while ! check_balancer; do sleep 1; done
102
103 ct_healthy_wait
104
105 OSDLIST=$(ceph osd tree-from $(hostname -s)| sed '1,2d' | awk '{print $1}')
106 for i in $OSDLIST; do
107 echo "Disable ceph-osd@${i}.service"
108 systemctl disable ceph-osd@${i}.service >/dev/null
109 while ! check_osd_disabled ${i}; do sleep 2; done
110 done
111
112 for i in $(ls /etc/systemd/system/ceph-osd@*.service); do
113 rm -f /etc/systemd/system/$i 2>/dev/null
114 while [ -f /etc/systemd/system/$i ]; do sleep 1; done
115 rm -rf /etc/systemd/system/$i.service.d 2>/dev/null
116 while [ -d /etc/systemd/system/$i.service.d ]; do sleep 1; done
117 done
118
119 ceph osd set norebalance
120 while ! check_flag "norebalance"; do sleep 1; done
121
122 ceph balancer off
123 while check_balancer; do sleep 1; done
124
125 _CT_MAX_BACKFILLS_INIT=$(ct-osd-config -g osd_max_backfills 2>/dev/null | head -1 | awk '{print $3}'|xargs)
126
127 ct-osd-config -s osd_max_backfills 1 > /dev/null
128 sleep 10
129 check_osd_config osd_max_backfills 1 || ct_logger "osd_max_backfills not set to 1"
130
131 for i in $OSDLIST; do
132 echo "Set Destroy and purge osd.${i}"
133 ceph osd destroy $i --yes-i-really-mean-it
134 sleep 2
135 ceph osd purge $i --yes-i-really-mean-it
136 sleep 2
137 check_osd_purged ${i} || ct_notify "OSD.${i} not Purged"
138 done
139
140 sleep 10
141
142 echo "Remapped"
143 for i in {1..3}; do
144 ct_cr=$(ct_get_current_remapped)
145 if [[ "$ct_cr" -eq "0" ]]; then
146 break
147 fi
148 ct-upmap-remapped | sh 2> /dev/null
149 sleep 10
150 done
151
152 ceph osd unset norebalance
153 while check_flag "norebalance"; do sleep 1; done
154
155 ct_healthy_wait 0
156
157 for i in $OSDLIST;do
158 echo Zap OSD.${i}
159 ceph-volume lvm zap --destroy --osd-id $i
160 while ! check_osd_zapped; do sleep 2; done
161 done
162
163 ceph balancer on
164 while ! check_balancer; do sleep 1; done
165
166 ct-osd-config -s osd_max_backfills $_CT_MAX_BACKFILLS_INIT
167 sleep 10
168 check_osd_config osd_max_backfills $_CT_MAX_BACKFILLS_INIT || ct_logger "osd_max_backfills not set to ${_CT_MAX_BACKFILLS_INIT}"
169
170 ceph osd unset noin
171 while check_flag "noin"; do sleep 1; done
172 ceph osd unset noout
173 while check_flag "noout"; do sleep 1; done
174
175 ct_on_exit 0