Debian Codegraph @

bin/ct-emptying-osd-server

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Default Values
3 #set -x
4 source /usr/share/ceph-tools/_ct-commonscip-shell source . . `/usr/share/ceph-tools/_ct-common`.
5
6 help_msgscip-shell shell ceph-tools 0.0.40 help_msg(). () {
7 printfscip-shell system . . 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_noexistscip-shell shell ceph-tools 0.0.40 osd_noexist().(){
21 ret=$(ceph osd crush dump |jqscip-shell system . . jq. '.devices[] | select(.id=='${1}')'|wcscip-shell system . . wc. -l)
22 return $ret
23 }
24
25 check_balancerscip-shell shell ceph-tools 0.0.40 check_balancer().(){
26 # Test balancer status
27 [scip-shell system . . `[`. "$(ceph balancer status | jqscip-shell system . . jq. .active)" == "true" ]
28 }
29
30 check_flagscip-shell shell ceph-tools 0.0.40 check_flag().(){
31 # Test flag
32 # Param 1: flag to test
33 [scip-shell system . . `[`. "$(ceph -s | grepscip-shell system . . grep. flags | grepscip-shell system . . grep. ${1} | wcscip-shell system . . wc. -l)" -eq "1" ]
34 }
35
36 check_osd_downscip-shell shell ceph-tools 0.0.40 check_osd_down().(){
37 # Test if OSD down
38 # Param 1: osdid
39 [scip-shell system . . `[`. "$(ceph osd tree -f json| jqscip-shell system . . jq. '.nodes[]|select(.id=='${1}').status')" == "\"down\"" ]
40 }
41
42 check_osd_outscip-shell shell ceph-tools 0.0.40 check_osd_out().(){
43 # Test if OSD out
44 # Param 1: osdid
45 [scip-shell system . . `[`. "$(ceph osd tree -f json| jqscip-shell system . . jq. '.nodes[]|select(.id=='${1}').reweight')" -eq "0" ]
46 }
47
48 check_osd_configscip-shell shell ceph-tools 0.0.40 check_osd_config().(){
49 # Test if OSD config
50 # Param 1: key to test
51 # Param 2: value to test
52 [scip-shell system . . `[`. "$(ct-osd-config -g ${1} 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -1 | awkscip-shell system . . awk. '{print $3}')" == "\"${2}\"" ]
53 }
54
55 check_osd_purgedscip-shell shell ceph-tools 0.0.40 check_osd_purged().(){
56 # Test if OSD out
57 # Param 1: osdid
58 HOST=$(hostnamescip-shell system . . hostname. -s)
59 [scip-shell system . . `[`. "$(ceph osd crush ls $HOST | grepscip-shell system . . grep. -e"^osd.${1}$" |wcscip-shell system . . wc. -l)" -eq "0" ]
60 }
61
62 check_osd_disabledscip-shell shell ceph-tools 0.0.40 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/nullscip-shell filesystem . . `/dev/null`.
66 }
67
68 check_osd_zappedscip-shell shell ceph-tools 0.0.40 check_osd_zapped().(){
69 # Test if OSD service is zapped
70 # Param 1: osdid
71 ! ceph-volume lvm list | grepscip-shell system . . grep. " osd id"| grepscip-shell system . . grep. $i
72 }
73
74 ct_help $@
75 shift $?
76 # Beginning of operations
77
78 ceph balancer off
79 while check_balancerscip-shell shell ceph-tools 0.0.40 check_balancer().; do sleepscip-shell system . . sleep. 1;done
80
81 ceph osd set noin
82 while ! check_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "noin"; do sleepscip-shell system . . sleep. 1; done
83 ceph osd set noout
84 while ! check_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "noout"; do sleepscip-shell system . . sleep. 1; done
85
86 OSDLIST=$(ceph osd tree-from $(hostnamescip-shell system . . hostname. -s) | sedscip-shell system . . sed. '1,2d' | awkscip-shell system . . awk. '{print $1}')
87 for i in $OSDLIST ;do
88 ct_healthy_wait
89 echoscip-shell system . . echo. "Set osd.${i} DOWN"
90 systemctl stop ceph-osd@${i}.service
91 while ! check_osd_downscip-shell shell ceph-tools 0.0.40 check_osd_down(). $i; do sleepscip-shell system . . sleep. 2; done
92 ceph osd out $i
93 while ! check_osd_outscip-shell shell ceph-tools 0.0.40 check_osd_out(). $i; do sleepscip-shell system . . sleep. 2; done
94 ct-upmap-remapped | shscip-shell system . . sh. 2> /dev/nullscip-shell filesystem . . `/dev/null`.
95 done
96
97
98 ct_healthy_wait
99 echoscip-shell system . . echo. "Set balancer On"
100 ceph balancer on
101 while ! check_balancerscip-shell shell ceph-tools 0.0.40 check_balancer().; do sleepscip-shell system . . sleep. 1; done
102
103 ct_healthy_wait
104
105 OSDLIST=$(ceph osd tree-from $(hostnamescip-shell system . . hostname. -s)| sedscip-shell system . . sed. '1,2d' | awkscip-shell system . . awk. '{print $1}')
106 for i in $OSDLIST; do
107 echoscip-shell system . . echo. "Disable ceph-osd@${i}.service"
108 systemctl disable ceph-osd@${i}.service >/dev/nullscip-shell filesystem . . `/dev/null`.
109 while ! check_osd_disabledscip-shell shell ceph-tools 0.0.40 check_osd_disabled(). ${i}; do sleepscip-shell system . . sleep. 2; done
110 done
111
112 for i in $(lsscip-shell system . . ls. /etc/systemd/system/ceph-osd@*.service); do
113 rmscip-shell system . . rm. -f /etc/systemd/system/$i 2>/dev/nullscip-shell filesystem . . `/dev/null`.
114 while [scip-shell system . . `[`. -f /etc/systemd/system/$i ]; do sleepscip-shell system . . sleep. 1; done
115 rmscip-shell system . . rm. -rf /etc/systemd/system/$i.service.d 2>/dev/nullscip-shell filesystem . . `/dev/null`.
116 while [scip-shell system . . `[`. -d /etc/systemd/system/$i.service.d ]; do sleepscip-shell system . . sleep. 1; done
117 done
118
119 ceph osd set norebalance
120 while ! check_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "norebalance"; do sleepscip-shell system . . sleep. 1; done
121
122 ceph balancer off
123 while check_balancerscip-shell shell ceph-tools 0.0.40 check_balancer().; do sleepscip-shell system . . sleep. 1; done
124
125 _CT_MAX_BACKFILLS_INIT=$(ct-osd-config -g osd_max_backfills 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -1 | awkscip-shell system . . awk. '{print $3}'|xargsscip-shell system . . xargs.)
126
127 ct-osd-config -s osd_max_backfills 1 > /dev/nullscip-shell filesystem . . `/dev/null`.
128 sleepscip-shell system . . sleep. 10
129 check_osd_configscip-shell shell ceph-tools 0.0.40 check_osd_config(). osd_max_backfills 1 || ct_logger "osd_max_backfills not set to 1"
130
131 for i in $OSDLIST; do
132 echoscip-shell system . . echo. "Set Destroy and purge osd.${i}"
133 ceph osd destroy $i --yes-i-really-mean-it
134 sleepscip-shell system . . sleep. 2
135 ceph osd purge $i --yes-i-really-mean-it
136 sleepscip-shell system . . sleep. 2
137 check_osd_purgedscip-shell shell ceph-tools 0.0.40 check_osd_purged(). ${i} || ct_notify "OSD.${i} not Purged"
138 done
139
140 sleepscip-shell system . . sleep. 10
141
142 echoscip-shell system . . 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 | shscip-shell system . . sh. 2> /dev/nullscip-shell filesystem . . `/dev/null`.
149 sleepscip-shell system . . sleep. 10
150 done
151
152 ceph osd unset norebalance
153 while check_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "norebalance"; do sleepscip-shell system . . sleep. 1; done
154
155 ct_healthy_wait 0
156
157 for i in $OSDLIST;do
158 echoscip-shell system . . echo. Zap OSD.${i}
159 ceph-volume lvm zap --destroy --osd-id $i
160 while ! check_osd_zappedscip-shell shell ceph-tools 0.0.40 check_osd_zapped().; do sleepscip-shell system . . sleep. 2; done
161 done
162
163 ceph balancer on
164 while ! check_balancerscip-shell shell ceph-tools 0.0.40 check_balancer().; do sleepscip-shell system . . sleep. 1; done
165
166 ct-osd-config -s osd_max_backfills $_CT_MAX_BACKFILLS_INIT
167 sleepscip-shell system . . sleep. 10
168 check_osd_configscip-shell shell ceph-tools 0.0.40 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_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "noin"; do sleepscip-shell system . . sleep. 1; done
172 ceph osd unset noout
173 while check_flagscip-shell shell ceph-tools 0.0.40 check_flag(). "noout"; do sleepscip-shell system . . sleep. 1; done
174
175 ct_on_exit 0