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

This commit is contained in:
Alena Prokharchyk 2013-09-19 10:26:59 -07:00
parent 160d980c72
commit 16493841ad

View File

@ -23,13 +23,14 @@
#set -x
usage() {
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
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
}
system=
router=
all=
vpc=
db=localhost
ms=localhost
user=root
@ -42,7 +43,7 @@ inzone=""
while getopts 'sarhnd:m:u:p:t:l:z:' OPTION
while getopts 'sarhnvd:m:u:p:t:l:z:' OPTION
do
case $OPTION in
s) system=1
@ -53,6 +54,8 @@ do
;;
a) all=1
;;
v) vpc=1
;;
d) db="$OPTARG"
;;
u) user="$OPTARG"
@ -317,6 +320,92 @@ restart_network(){
}
restart_vpc(){
echo -e "INFO: Restarting vpc with id $1"
echo "INFO: Restarting vpc with id $1" >>$LOGFILE
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'}`
if [ "$jobid" == "" ]; then
echo "ERROR: Failed to restart vpc with id $1" >>$LOGFILE
echo 2
return
fi
jobresult=$(query_async_job_result $jobid)
if [ "$jobresult" != "1" ]; then
echo -e "ERROR: Failed to restart vpc with id $1 \n"
echo "ERROR: Failed to restart vpc with id $1" >>$LOGFILE
else
echo -e "INFO: Successfully restarted vpc with id $1 \n"
echo "INFO: Successfully restarted vpc with id $1" >>$LOGFILE
fi
}
restart_vpcs(){
vpcs=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vpc WHERE removed is null$zone"`)
length_vpcs=(${#vpcs[@]})
echo -e "\nRestarting $length_vpcs vpcs... "
echo -e "Restarting $length_vpcs vpcs... " >>$LOGFILE
#Spawn restart vpcs in parallel - run commands in <n> chunks - number of threads is configurable
pids=()
for d in "${vpcs[@]}"; do
restart_vpc $d &
pids=( "${pids[@]}" $! )
length_pids=(${#pids[@]})
unfinishedPids=(${#pids[@]})
if [ $maxthreads -gt $length_vpcs ]; then
maxthreads=$length_vpcs
fi
if [ $length_pids -ge $maxthreads ]; then
while [ $unfinishedPids -gt 0 ]; do
sleep 10
count=0
for (( i = 0 ; i < $length_pids; i++ )); do
if ! ps ax | grep -v grep | grep ${pids[$i]} > /dev/null; then
count=`expr $count + 1`
fi
done
if [ $count -eq $unfinishedPids ]; then
unfinishedPids=0
fi
done
#remove all elements from pids
if [ $unfinishedPids -eq 0 ]; then
pids=()
length_pids=(${#pids[@]})
fi
fi
done
if [ "$length_vpcs" == "0" ];then
echo -e "No vpcs found \n" >>$LOGFILE
else
while [ $unfinishedPids -gt 0 ]; do
sleep 10
done
echo -e "Done restarting vpcs$inzone. \n"
echo -e "Done restarting vpcs$inzone. \n" >>$LOGFILE
fi
}
query_async_job_result() {
while [ 1 ]
do
@ -329,7 +418,7 @@ sleep 5
done
}
if [ "$system$router$all$help$redundant" == "" ]
if [ "$system$router$all$help$redundant$vpc" == "" ]
then
usage
exit
@ -361,3 +450,10 @@ if [ "$redundant" == "1" ]
then
restart_networks
fi
if [ "$vpc" == "1" ]
then
restart_vpcs
fi