|
18 | 18 | # under the License. |
19 | 19 |
|
20 | 20 |
|
21 | | -. /etc/rc.d/init.d/functions |
22 | | - |
23 | 21 | #set -x |
24 | 22 |
|
25 | 23 | usage() { |
@@ -117,168 +115,167 @@ prepare_ids_clause() { |
117 | 115 |
|
118 | 116 | stop_start_system() { |
119 | 117 | prepare_ids_clause |
120 | | -secondary=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from $vmtable where state=\"Running\" and type=\"SecondaryStorageVm\"$zone$vmidsclause"`) |
121 | | -console=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from $vmtable where state=\"Running\" and type=\"ConsoleProxy\"$zone$vmidsclause"`) |
122 | | -length_secondary=(${#secondary[@]}) |
123 | | -length_console=(${#console[@]}) |
124 | | - |
125 | | - |
126 | | -echo -e "\nStopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." |
127 | | -echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." >>$LOGFILE |
128 | | - |
129 | | -for d in "${secondary[@]}"; do |
130 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping secondary storage vm with id $d" >>$LOGFILE |
131 | | - jobresult=$(send_request stopSystemVm $d) |
132 | | - if [ "$jobresult" != "1" ]; then |
133 | | - echo -e "ERROR: Failed to stop secondary storage vm with id $d \n" |
134 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to stop secondary storage vm with id $d" >>$LOGFILE |
135 | | - else |
136 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Starting secondary storage vm with id $d" >>$LOGFILE |
137 | | - jobresult=$(send_request startSystemVm $d SSVM) |
138 | | - if [ "$jobresult" != "1" ]; then |
139 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start secondary storage vm with id $d" >>$LOGFILE |
140 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start secondary storage vm with id $d" >>$LOGFILE |
141 | | - fi |
142 | | - fi |
143 | | -done |
| 118 | + secondary=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from $vmtable where state=\"Running\" and type=\"SecondaryStorageVm\"$zone$vmidsclause"`) |
| 119 | + console=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from $vmtable where state=\"Running\" and type=\"ConsoleProxy\"$zone$vmidsclause"`) |
| 120 | + length_secondary=(${#secondary[@]}) |
| 121 | + length_console=(${#console[@]}) |
| 122 | + |
| 123 | + |
| 124 | + echo -e "\nStopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." |
| 125 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." >>$LOGFILE |
| 126 | + |
| 127 | + for d in "${secondary[@]}"; do |
| 128 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping secondary storage vm with id $d" >>$LOGFILE |
| 129 | + jobresult=$(send_request stopSystemVm $d) |
| 130 | + if [ "$jobresult" != "1" ]; then |
| 131 | + echo -e "ERROR: Failed to stop secondary storage vm with id $d \n" |
| 132 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to stop secondary storage vm with id $d" >>$LOGFILE |
| 133 | + else |
| 134 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Starting secondary storage vm with id $d" >>$LOGFILE |
| 135 | + jobresult=$(send_request startSystemVm $d SSVM) |
| 136 | + if [ "$jobresult" != "1" ]; then |
| 137 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start secondary storage vm with id $d" >>$LOGFILE |
| 138 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start secondary storage vm with id $d" >>$LOGFILE |
| 139 | + fi |
| 140 | + fi |
| 141 | + done |
144 | 142 |
|
145 | | -if [ "$length_secondary" == "0" ];then |
146 | | - echo -e "No running secondary storage vms found \n" |
147 | | -else |
148 | | - echo -e "Done stopping and starting secondary storage vm(s)$inzone$withids" |
149 | | - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting secondary storage vm(s)$inzone$withids." >>$LOGFILE |
150 | | -fi |
| 143 | + if [ "$length_secondary" == "0" ];then |
| 144 | + echo -e "No running secondary storage vms found \n" |
| 145 | + else |
| 146 | + echo -e "Done stopping and starting secondary storage vm(s)$inzone$withids" |
| 147 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting secondary storage vm(s)$inzone$withids." >>$LOGFILE |
| 148 | + fi |
151 | 149 |
|
152 | | -echo -e "\nStopping and starting $length_console console proxy vm(s)$inzone$withids..." |
153 | | -echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_console console proxy vm(s)$inzone$withids..." >>$LOGFILE |
| 150 | + echo -e "\nStopping and starting $length_console console proxy vm(s)$inzone$withids..." |
| 151 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_console console proxy vm(s)$inzone$withids..." >>$LOGFILE |
| 152 | + |
| 153 | + for d in "${console[@]}"; do |
| 154 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping console proxy with id $d" >>$LOGFILE |
| 155 | + jobresult=$(send_request stopSystemVm $d) |
| 156 | + if [ "$jobresult" != "1" ]; then |
| 157 | + echo -e "ERROR: Failed to stop console proxy vm with id $d \n" |
| 158 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to stop console proxy vm with id $d" >>$LOGFILE |
| 159 | + else |
| 160 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Starting console proxy vm with id $d" >>$LOGFILE |
| 161 | + jobresult=$(send_request startSystemVm $d consoleProxy) |
| 162 | + if [ "$jobresult" != "1" ]; then |
| 163 | + echo -e "ERROR: Failed to start console proxy vm with id $d \n" |
| 164 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start console proxy vm with id $d" >>$LOGFILE |
| 165 | + fi |
| 166 | + fi |
| 167 | + done |
154 | 168 |
|
155 | | -for d in "${console[@]}"; do |
156 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping console proxy with id $d" >>$LOGFILE |
157 | | - jobresult=$(send_request stopSystemVm $d) |
158 | | - if [ "$jobresult" != "1" ]; then |
159 | | - echo -e "ERROR: Failed to stop console proxy vm with id $d \n" |
160 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to stop console proxy vm with id $d" >>$LOGFILE |
| 169 | + if [ "$length_console" == "0" ];then |
| 170 | + echo -e "No running console proxy vms found \n" |
161 | 171 | else |
162 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Starting console proxy vm with id $d" >>$LOGFILE |
163 | | - jobresult=$(send_request startSystemVm $d consoleProxy) |
164 | | - if [ "$jobresult" != "1" ]; then |
165 | | - echo -e "ERROR: Failed to start console proxy vm with id $d \n" |
166 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to start console proxy vm with id $d" >>$LOGFILE |
167 | | - fi |
| 172 | + echo "Done stopping and starting console proxy vm(s) $inzone$withids." |
| 173 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting console proxy vm(s) $inzone$withids." >>$LOGFILE |
168 | 174 | fi |
169 | | -done |
170 | | - |
171 | | -if [ "$length_console" == "0" ];then |
172 | | - echo -e "No running console proxy vms found \n" |
173 | | -else |
174 | | - echo "Done stopping and starting console proxy vm(s) $inzone$withids." |
175 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting console proxy vm(s) $inzone$withids." >>$LOGFILE |
176 | | -fi |
177 | 175 | } |
178 | 176 |
|
179 | 177 | stop_start_router() { |
180 | 178 | prepare_ids_clause |
181 | | - router=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vm_instance where state=\"Running\" and type=\"DomainRouter\"$zone$vmidsclause"`) |
182 | | - length_router=(${#router[@]}) |
| 179 | + router=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vm_instance where state=\"Running\" and type=\"DomainRouter\"$zone$vmidsclause"`) |
| 180 | + length_router=(${#router[@]}) |
183 | 181 |
|
184 | | - echo -e "\nStopping and starting $length_router running routing vm(s)$inzone$withids... " |
185 | | - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone$withids... " >>$LOGFILE |
| 182 | + echo -e "\nStopping and starting $length_router running routing vm(s)$inzone$withids... " |
| 183 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone$withids... " >>$LOGFILE |
186 | 184 |
|
187 | | - #Spawn reboot router in parallel - run commands in <n> chunks - number of threads is configurable |
| 185 | + #Spawn reboot router in parallel - run commands in <n> chunks - number of threads is configurable |
188 | 186 |
|
189 | | - pids=() |
190 | | - for d in "${router[@]}"; do |
| 187 | + pids=() |
| 188 | + for d in "${router[@]}"; do |
191 | 189 |
|
192 | | - reboot_router $d & |
| 190 | + reboot_router $d & |
193 | 191 |
|
194 | | - pids=( "${pids[@]}" $! ) |
| 192 | + pids=( "${pids[@]}" $! ) |
195 | 193 |
|
196 | | - length_pids=(${#pids[@]}) |
197 | | - unfinishedPids=(${#pids[@]}) |
| 194 | + length_pids=(${#pids[@]}) |
| 195 | + unfinishedPids=(${#pids[@]}) |
198 | 196 |
|
199 | | - if [ $maxthreads -gt $length_router ]; then |
200 | | - maxthreads=$length_router |
201 | | - fi |
| 197 | + if [ $maxthreads -gt $length_router ]; then |
| 198 | + maxthreads=$length_router |
| 199 | + fi |
202 | 200 |
|
203 | | - if [ $length_pids -ge $maxthreads ]; then |
204 | | - while [ $unfinishedPids -gt 0 ]; do |
205 | | - sleep 10 |
206 | | - count=0 |
207 | | - for (( i = 0 ; i < $length_pids; i++ )); do |
208 | | - if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then |
209 | | - count=`expr $count + 1` |
210 | | - fi |
211 | | - done |
| 201 | + if [ $length_pids -ge $maxthreads ]; then |
| 202 | + while [ $unfinishedPids -gt 0 ]; do |
| 203 | + sleep 10 |
| 204 | + count=0 |
| 205 | + for (( i = 0 ; i < $length_pids; i++ )); do |
| 206 | + if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then |
| 207 | + count=`expr $count + 1` |
| 208 | + fi |
| 209 | + done |
212 | 210 |
|
213 | | - if [ $count -eq $unfinishedPids ]; then |
214 | | - unfinishedPids=0 |
215 | | - fi |
| 211 | + if [ $count -eq $unfinishedPids ]; then |
| 212 | + unfinishedPids=0 |
| 213 | + fi |
216 | 214 |
|
217 | | - done |
| 215 | + done |
218 | 216 |
|
219 | | - #remove all elements from pids |
220 | | - if [ $unfinishedPids -eq 0 ]; then |
221 | | - pids=() |
222 | | - length_pids=(${#pids[@]}) |
223 | | - fi |
| 217 | + #remove all elements from pids |
| 218 | + if [ $unfinishedPids -eq 0 ]; then |
| 219 | + pids=() |
| 220 | + length_pids=(${#pids[@]}) |
| 221 | + fi |
224 | 222 |
|
225 | | - fi |
| 223 | + fi |
226 | 224 |
|
227 | | - done |
| 225 | + done |
228 | 226 |
|
229 | | - if [ "$length_router" == "0" ];then |
230 | | - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No running router vms found \n" >>$LOGFILE |
231 | | - else |
232 | | - while [ $unfinishedPids -gt 0 ]; do |
233 | | - sleep 10 |
234 | | - done |
| 227 | + if [ "$length_router" == "0" ];then |
| 228 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] No running router vms found \n" >>$LOGFILE |
| 229 | + else |
| 230 | + while [ $unfinishedPids -gt 0 ]; do |
| 231 | + sleep 10 |
| 232 | + done |
235 | 233 |
|
236 | | - echo -e "Done restarting router(s)$inzone$withids. \n" |
237 | | - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone$withids. \n" >>$LOGFILE |
| 234 | + echo -e "Done restarting router(s)$inzone$withids. \n" |
| 235 | + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone$withids. \n" >>$LOGFILE |
238 | 236 |
|
239 | | - fi |
| 237 | + fi |
240 | 238 | } |
241 | 239 |
|
242 | 240 | stop_start_all() { |
243 | | -stop_start_system |
244 | | -stop_start_router |
| 241 | + stop_start_system |
| 242 | + stop_start_router |
245 | 243 | } |
246 | 244 |
|
247 | 245 | send_request(){ |
248 | | - jobid=`curl -sS "http://$ms:8096/?command=$1&id=$2&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}` |
249 | | - if [ "$jobid" == "" ]; then |
250 | | - echo 2 |
251 | | - return |
252 | | - fi |
253 | | - jobresult=$(query_async_job_result $jobid) |
| 246 | + jobid=`curl -sS "http://$ms:8096/?command=$1&id=$2&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}` |
| 247 | + if [ "$jobid" == "" ]; then |
| 248 | + echo 2 |
| 249 | + return |
| 250 | + fi |
| 251 | + jobresult=$(query_async_job_result $jobid) |
254 | 252 | if [ "$jobresult" != "1" ]; then |
255 | 253 | echo -e "ERROR: Failed to $1 id=$2; jobId is $jobid \n" |
256 | 254 | echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to $1 id=$2; jobId is $jobid" >>$LOGFILE |
257 | 255 | fi |
258 | | - echo $jobresult |
| 256 | + echo $jobresult |
259 | 257 | } |
260 | 258 |
|
261 | 259 |
|
262 | 260 | reboot_router(){ |
263 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Restarting router with id $1" >>$LOGFILE |
264 | | - jobid=`curl -sS "http://$ms:8096/?command=rebootRouter&id=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}` |
265 | | - if [ "$jobid" == "" ]; then |
266 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to restart domainRouter with id $1; unable to submit the job" >>$LOGFILE |
267 | | - echo 2 |
268 | | - return |
269 | | - fi |
270 | | - |
271 | | - jobresult=$(query_async_job_result $jobid) |
272 | | - |
273 | | - if [ "$jobresult" != "1" ]; then |
274 | | - echo -e "ERROR: Failed to restart domainRouter with id $1 \n" |
275 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to restart domainRouter with id $1; jobId $jobid" >>$LOGFILE |
276 | | - exit 0 |
277 | | - else |
278 | | - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Successfully restarted domainRouter with id $1; jobId $jobid" >>$LOGFILE |
279 | | - exit 0 |
280 | | - fi |
| 261 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Restarting router with id $1" >>$LOGFILE |
| 262 | + jobid=`curl -sS "http://$ms:8096/?command=rebootRouter&id=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}` |
| 263 | + if [ "$jobid" == "" ]; then |
| 264 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to restart domainRouter with id $1; unable to submit the job" >>$LOGFILE |
| 265 | + echo 2 |
| 266 | + return |
| 267 | + fi |
281 | 268 |
|
| 269 | + jobresult=$(query_async_job_result $jobid) |
| 270 | + |
| 271 | + if [ "$jobresult" != "1" ]; then |
| 272 | + echo -e "ERROR: Failed to restart domainRouter with id $1 \n" |
| 273 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] ERROR: Failed to restart domainRouter with id $1; jobId $jobid" >>$LOGFILE |
| 274 | + exit 0 |
| 275 | + else |
| 276 | + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Successfully restarted domainRouter with id $1; jobId $jobid" >>$LOGFILE |
| 277 | + exit 0 |
| 278 | + fi |
282 | 279 | } |
283 | 280 |
|
284 | 281 | restart_networks(){ |
@@ -450,21 +447,21 @@ restart_vpcs(){ |
450 | 447 | } |
451 | 448 |
|
452 | 449 | query_async_job_result() { |
453 | | -while [ 1 ] |
454 | | -do |
455 | | - jobstatus=`curl -sS "http://$ms:8096/?command=queryAsyncJobResult&jobId=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F, {'print $4'} | awk -F: {'print $2'}` |
456 | | - if [ "$jobstatus" != "0" ]; then |
457 | | - echo $jobstatus |
458 | | - break |
459 | | - fi |
460 | | -sleep 5 |
461 | | -done |
| 450 | + while [ 1 ] |
| 451 | + do |
| 452 | + jobstatus=`curl -sS "http://$ms:8096/?command=queryAsyncJobResult&jobId=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F, {'print $4'} | awk -F: {'print $2'}` |
| 453 | + if [ "$jobstatus" != "0" ]; then |
| 454 | + echo $jobstatus |
| 455 | + break |
| 456 | + fi |
| 457 | + sleep 5 |
| 458 | + done |
462 | 459 | } |
463 | 460 |
|
464 | 461 | if [ "$system$router$all$help$redundant$vpc" == "" ] |
465 | 462 | then |
466 | | - usage |
467 | | - exit |
| 463 | + usage |
| 464 | + exit |
468 | 465 | fi |
469 | 466 |
|
470 | 467 | if [ "$help" == "1" ] |
|
0 commit comments