From ef8eb5230f04efd765736162f391fd9c630c97e4 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 27 Jul 2022 16:24:02 +0530 Subject: [PATCH 1/5] scripts: parametrize systemvm, router restart Fixes #6220 Signed-off-by: Abhishek Kumar --- setup/bindir/cloud-sysvmadm.in | 56 +++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/setup/bindir/cloud-sysvmadm.in b/setup/bindir/cloud-sysvmadm.in index 4c67c31085d1..bdac1fc6c2c0 100755 --- a/setup/bindir/cloud-sysvmadm.in +++ b/setup/bindir/cloud-sysvmadm.in @@ -23,7 +23,7 @@ #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] [-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 + printf "\nThe tool stopping/starting running system vms and domain routers \n\nUsage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-n] [-z] [-i] [-j] [-v] [-i] [-j]\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 -i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works ony when restarting SSVMs, CPVMs or VRs\n -j - do restart on instances from the specified database table. If not specified, restart will apply on instances present in cloud.vm_instance database table. Works ony when restarting SSVMs, CPVMs or VRs\n\n" $(basename $0) >&2 } @@ -40,10 +40,14 @@ maxthreads=10 LOGFILE=cloud.log zone="" inzone="" +vmids="" +vmidsclause="" +withids="" +vmtable="vm_instance" -while getopts 'sarhnvd:m:u:p:t:l:z:' OPTION +while getopts 'sarhnvd:m:u:p:t:l:z:i:j:' OPTION do case $OPTION in s) system=1 @@ -72,21 +76,36 @@ do ;; z) zone=" AND data_center_id=""$OPTARG" inzone=" in zone id=""$OPTARG" + ;; + i) vmids="$OPTARG" + withids=" with id=""$OPTARG" + ;; + j) vmtable="$OPTARG" esac done - +prapare_ids_clause() { + if [[ ! -z "$vmidsclause" ]]; then + return + fi + vmidsclause="" + if [[ ! -z "$vmids" ]]; then + vmidsclause=" AND uuid IN ('$vmids')" + vmidsclause=${vmidsclause/,/"','"} + fi +} stop_start_system() { -secondary=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vm_instance where state=\"Running\" and type=\"SecondaryStorageVm\"$zone"`) -console=(`mysql -h $db --user=$user --password=$password --skip-column-names -U cloud -e "select id from vm_instance where state=\"Running\" and type=\"ConsoleProxy\"$zone"`) + prapare_ids_clause +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"`) +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"`) length_secondary=(${#secondary[@]}) length_console=(${#console[@]}) -echo -e "\nStopping and starting $length_secondary secondary storage vm(s)$inzone..." -echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_secondary secondary storage vm(s)$inzone..." >>$LOGFILE +echo -e "\nStopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." +echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_secondary secondary storage vm(s)$inzone$withids..." >>$LOGFILE for d in "${secondary[@]}"; do echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping secondary storage vm with id $d" >>$LOGFILE @@ -107,12 +126,12 @@ done if [ "$length_secondary" == "0" ];then echo -e "No running secondary storage vms found \n" else - echo -e "Done stopping and starting secondary storage vm(s)$inzone" - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting secondary storage vm(s)$inzone." >>$LOGFILE + echo -e "Done stopping and starting secondary storage vm(s)$inzone$withids" + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting secondary storage vm(s)$inzone$withids." >>$LOGFILE fi -echo -e "\nStopping and starting $length_console console proxy vm(s)$inzone..." -echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_console console proxy vm(s)$inzone..." >>$LOGFILE +echo -e "\nStopping and starting $length_console console proxy vm(s)$inzone$withids..." +echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_console console proxy vm(s)$inzone$withids..." >>$LOGFILE for d in "${console[@]}"; do echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping console proxy with id $d" >>$LOGFILE @@ -133,17 +152,18 @@ done if [ "$length_console" == "0" ];then echo -e "No running console proxy vms found \n" else - echo "Done stopping and starting console proxy vm(s) $inzone." - echo "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting console proxy vm(s) $inzone." >>$LOGFILE + echo "Done stopping and starting console proxy vm(s) $inzone$withids." + echo "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting console proxy vm(s) $inzone$withids." >>$LOGFILE fi } stop_start_router() { - 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"`) + prapare_ids_clause + 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"`) length_router=(${#router[@]}) - echo -e "\nStopping and starting $length_router running routing vm(s)$inzone... " - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone... " >>$LOGFILE + echo -e "\nStopping and starting $length_router running routing vm(s)$inzone$withids... " + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone$withids... " >>$LOGFILE #Spawn reboot router in parallel - run commands in chunks - number of threads is configurable @@ -194,8 +214,8 @@ stop_start_router() { sleep 10 done - echo -e "Done restarting router(s)$inzone. \n" - echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone. \n" >>$LOGFILE + echo -e "Done restarting router(s)$inzone$withids. \n" + echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone$withids. \n" >>$LOGFILE fi } From 1340931806d3c134ba6e0206c91babe787123da3 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 17 Aug 2022 15:15:15 +0530 Subject: [PATCH 2/5] typo in method name Signed-off-by: Abhishek Kumar --- setup/bindir/cloud-sysvmadm.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/bindir/cloud-sysvmadm.in b/setup/bindir/cloud-sysvmadm.in index bdac1fc6c2c0..7388b4d63873 100755 --- a/setup/bindir/cloud-sysvmadm.in +++ b/setup/bindir/cloud-sysvmadm.in @@ -85,7 +85,7 @@ do done -prapare_ids_clause() { +prepare_ids_clause() { if [[ ! -z "$vmidsclause" ]]; then return fi @@ -97,7 +97,7 @@ prapare_ids_clause() { } stop_start_system() { - prapare_ids_clause + prepare_ids_clause 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"`) 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"`) length_secondary=(${#secondary[@]}) @@ -158,7 +158,7 @@ fi } stop_start_router() { - prapare_ids_clause + prepare_ids_clause 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"`) length_router=(${#router[@]}) From 53242c19bb24c0a3e70d62373a5b87cd3c6d8743 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 13 Dec 2022 16:34:43 +0530 Subject: [PATCH 3/5] refactor usage Signed-off-by: Abhishek Kumar --- setup/bindir/cloud-sysvmadm.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/setup/bindir/cloud-sysvmadm.in b/setup/bindir/cloud-sysvmadm.in index 7388b4d63873..26bb1b6087f4 100755 --- a/setup/bindir/cloud-sysvmadm.in +++ b/setup/bindir/cloud-sysvmadm.in @@ -23,7 +23,26 @@ #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] [-i] [-j] [-v] [-i] [-j]\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 -i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works ony when restarting SSVMs, CPVMs or VRs\n -j - do restart on instances from the specified database table. If not specified, restart will apply on instances present in cloud.vm_instance database table. Works ony when restarting SSVMs, CPVMs or VRs\n\n" $(basename $0) >&2 + usage_content=" + The tool for stopping/starting running system vms and domain routers + + Usage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-n] [-z] [-i] [-j] [-v] [-i] [-j] + + -d - cloud DB server ip address, defaulted to localhost if not specified + -u - user name to access cloud DB, defaulted to \"root\" if not specified + -p - cloud DB user password, defaulted to no password if not specified + -m - the ip address of management server, defaulted to localhost if not specified + -s - stop then start all running SSVMs and Console Proxies + -r - stop then start all running Virtual Routers + -a - stop then start all running SSVMs, Console Proxies, and Virtual Routers + -n - restart all Guest networks + -t - number of parallel threads used for stopping Domain Routers. Default is 10 + -l - log file location. Default is cloud.log under current directory + -z - do restart only for the instances in the specific zone. If not specified, restart will apply to instances in all zones + -v - do restart all VPCs in the entire system + -i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works ony when restarting SSVMs, CPVMs or VRs + -j - do restart on instances from the specified database table. If not specified, restart will apply on instances present in cloud.vm_instance database table. Works ony when restarting SSVMs, CPVMs or VRs\n\n" + printf "$usage_content" "$(basename $0)" >&2 } From fddd58dd5e254c5430d446b7e3e3d9ae7b32de63 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 13 Dec 2022 16:42:44 +0530 Subject: [PATCH 4/5] fix Signed-off-by: Abhishek Kumar --- setup/bindir/cloud-sysvmadm.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/bindir/cloud-sysvmadm.in b/setup/bindir/cloud-sysvmadm.in index 26bb1b6087f4..3f02d22cb6e4 100755 --- a/setup/bindir/cloud-sysvmadm.in +++ b/setup/bindir/cloud-sysvmadm.in @@ -26,7 +26,7 @@ usage() { usage_content=" The tool for stopping/starting running system vms and domain routers - Usage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-t] [-n] [-z] [-i] [-j] [-v] [-i] [-j] + Usage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-n] [-t] [-l] [-z] [-v] [-i] [-j] -d - cloud DB server ip address, defaulted to localhost if not specified -u - user name to access cloud DB, defaulted to \"root\" if not specified From 7f67ed2a7e3566132a313ab6737751c88c4975aa Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 13 Dec 2022 16:44:04 +0530 Subject: [PATCH 5/5] typo Signed-off-by: Abhishek Kumar --- setup/bindir/cloud-sysvmadm.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/bindir/cloud-sysvmadm.in b/setup/bindir/cloud-sysvmadm.in index 3f02d22cb6e4..e826deaf6ff8 100755 --- a/setup/bindir/cloud-sysvmadm.in +++ b/setup/bindir/cloud-sysvmadm.in @@ -40,8 +40,8 @@ usage() { -l - log file location. Default is cloud.log under current directory -z - do restart only for the instances in the specific zone. If not specified, restart will apply to instances in all zones -v - do restart all VPCs in the entire system - -i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works ony when restarting SSVMs, CPVMs or VRs - -j - do restart on instances from the specified database table. If not specified, restart will apply on instances present in cloud.vm_instance database table. Works ony when restarting SSVMs, CPVMs or VRs\n\n" + -i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works only when restarting SSVMs, CPVMs or VRs + -j - do restart on instances from the specified database table. If not specified, restart will apply on instances present in cloud.vm_instance database table. Works only when restarting SSVMs, CPVMs or VRs\n\n" printf "$usage_content" "$(basename $0)" >&2 }