Skip to content

Commit 1649384

Browse files
author
Alena Prokharchyk
committed
Fixed sysvmadm helper script (responsible for restarting/recreating VRs when needed on upgraded setups due to template changes) to have -v option. When -v is specified, all VPCs in the system will get restarted. As a part of the restart, VPC routers will get recreated
1 parent 160d980 commit 1649384

1 file changed

Lines changed: 99 additions & 3 deletions

File tree

setup/bindir/cloud-sysvmadm.in

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
#set -x
2424

2525
usage() {
26-
printf "\nThe tool stopping/starting running system vms and domain routers \n\nUsage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-n] [-z]\n\n -d - cloud DB server ip address, defaulted to localhost if not specified \n -u - user name to access cloud DB, defaulted to "root" if not specified \n -p - cloud DB user password, defaulted to no password if not specified \n\n -m - the ip address of management server, defaulted to localhost if not specified\n\n -s - stop then start all running SSVMs and Console Proxies \n -r - stop then start all running Virtual Routers\n -a - stop then start all running SSVMs, Console Proxies, and Virtual Routers \n -n - restart all Guest networks \n -t - number of parallel threads used for stopping Domain Routers. Default is 10.\n -l - log file location. Default is cloud.log under current directory.\n -z - do restart only for the instances in the specific zone. If not specified, restart will apply to instances in all zones\n\n" $(basename $0) >&2
26+
printf "\nThe tool stopping/starting running system vms and domain routers \n\nUsage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-n] [-z] [-v]\n\n -d - cloud DB server ip address, defaulted to localhost if not specified \n -u - user name to access cloud DB, defaulted to "root" if not specified \n -p - cloud DB user password, defaulted to no password if not specified \n\n -m - the ip address of management server, defaulted to localhost if not specified\n\n -s - stop then start all running SSVMs and Console Proxies \n -r - stop then start all running Virtual Routers\n -a - stop then start all running SSVMs, Console Proxies, and Virtual Routers \n -n - restart all Guest networks \n -t - number of parallel threads used for stopping Domain Routers. Default is 10.\n -l - log file location. Default is cloud.log under current directory.\n -z - do restart only for the instances in the specific zone. If not specified, restart will apply to instances in all zones\n -v - do restart all VPCs in the entire system\n\n" $(basename $0) >&2
2727
}
2828

2929

3030
system=
3131
router=
3232
all=
33+
vpc=
3334
db=localhost
3435
ms=localhost
3536
user=root
@@ -42,7 +43,7 @@ inzone=""
4243

4344

4445

45-
while getopts 'sarhnd:m:u:p:t:l:z:' OPTION
46+
while getopts 'sarhnvd:m:u:p:t:l:z:' OPTION
4647
do
4748
case $OPTION in
4849
s) system=1
@@ -53,6 +54,8 @@ do
5354
;;
5455
a) all=1
5556
;;
57+
v) vpc=1
58+
;;
5659
d) db="$OPTARG"
5760
;;
5861
u) user="$OPTARG"
@@ -317,6 +320,92 @@ restart_network(){
317320

318321
}
319322

323+
324+
restart_vpc(){
325+
echo -e "INFO: Restarting vpc with id $1"
326+
echo "INFO: Restarting vpc with id $1" >>$LOGFILE
327+
jobid=`curl -sS "http://$ms:8096/?command=restartVPC&id=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}`
328+
if [ "$jobid" == "" ]; then
329+
echo "ERROR: Failed to restart vpc with id $1" >>$LOGFILE
330+
echo 2
331+
return
332+
fi
333+
334+
jobresult=$(query_async_job_result $jobid)
335+
336+
if [ "$jobresult" != "1" ]; then
337+
echo -e "ERROR: Failed to restart vpc with id $1 \n"
338+
echo "ERROR: Failed to restart vpc with id $1" >>$LOGFILE
339+
else
340+
echo -e "INFO: Successfully restarted vpc with id $1 \n"
341+
echo "INFO: Successfully restarted vpc with id $1" >>$LOGFILE
342+
fi
343+
}
344+
345+
346+
restart_vpcs(){
347+
vpcs=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vpc WHERE removed is null$zone"`)
348+
length_vpcs=(${#vpcs[@]})
349+
350+
echo -e "\nRestarting $length_vpcs vpcs... "
351+
echo -e "Restarting $length_vpcs vpcs... " >>$LOGFILE
352+
353+
#Spawn restart vpcs in parallel - run commands in <n> chunks - number of threads is configurable
354+
355+
pids=()
356+
for d in "${vpcs[@]}"; do
357+
358+
restart_vpc $d &
359+
360+
pids=( "${pids[@]}" $! )
361+
362+
length_pids=(${#pids[@]})
363+
unfinishedPids=(${#pids[@]})
364+
365+
if [ $maxthreads -gt $length_vpcs ]; then
366+
maxthreads=$length_vpcs
367+
fi
368+
369+
if [ $length_pids -ge $maxthreads ]; then
370+
while [ $unfinishedPids -gt 0 ]; do
371+
sleep 10
372+
count=0
373+
for (( i = 0 ; i < $length_pids; i++ )); do
374+
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
375+
count=`expr $count + 1`
376+
fi
377+
done
378+
379+
if [ $count -eq $unfinishedPids ]; then
380+
unfinishedPids=0
381+
fi
382+
383+
done
384+
385+
#remove all elements from pids
386+
if [ $unfinishedPids -eq 0 ]; then
387+
pids=()
388+
length_pids=(${#pids[@]})
389+
fi
390+
391+
fi
392+
393+
done
394+
395+
396+
if [ "$length_vpcs" == "0" ];then
397+
echo -e "No vpcs found \n" >>$LOGFILE
398+
else
399+
while [ $unfinishedPids -gt 0 ]; do
400+
sleep 10
401+
done
402+
403+
echo -e "Done restarting vpcs$inzone. \n"
404+
echo -e "Done restarting vpcs$inzone. \n" >>$LOGFILE
405+
406+
fi
407+
}
408+
320409
query_async_job_result() {
321410
while [ 1 ]
322411
do
@@ -329,7 +418,7 @@ sleep 5
329418
done
330419
}
331420

332-
if [ "$system$router$all$help$redundant" == "" ]
421+
if [ "$system$router$all$help$redundant$vpc" == "" ]
333422
then
334423
usage
335424
exit
@@ -361,3 +450,10 @@ if [ "$redundant" == "1" ]
361450
then
362451
restart_networks
363452
fi
453+
454+
if [ "$vpc" == "1" ]
455+
then
456+
restart_vpcs
457+
fi
458+
459+

0 commit comments

Comments
 (0)