Skip to content

Commit 87b25b9

Browse files
authored
scripts: parametrize systemvm, router restart (#6574)
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 41717b0 commit 87b25b9

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

setup/bindir/cloud-sysvmadm.in

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@
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] [-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
26+
usage_content="
27+
The tool for stopping/starting running system vms and domain routers
28+
29+
Usage: %s: [-d] [-u] [-p] [-m] [-s] [-r] [-a] [-n] [-t] [-l] [-z] [-v] [-i] [-j]
30+
31+
-d - cloud DB server ip address, defaulted to localhost if not specified
32+
-u - user name to access cloud DB, defaulted to \"root\" if not specified
33+
-p - cloud DB user password, defaulted to no password if not specified
34+
-m - the ip address of management server, defaulted to localhost if not specified
35+
-s - stop then start all running SSVMs and Console Proxies
36+
-r - stop then start all running Virtual Routers
37+
-a - stop then start all running SSVMs, Console Proxies, and Virtual Routers
38+
-n - restart all Guest networks
39+
-t - number of parallel threads used for stopping Domain Routers. Default is 10
40+
-l - log file location. Default is cloud.log under current directory
41+
-z - do restart only for the instances in the specific zone. If not specified, restart will apply to instances in all zones
42+
-v - do restart all VPCs in the entire system
43+
-i - do restart on instances with specific IDs. Comma-separated instance IDs to be provided. Works only when restarting SSVMs, CPVMs or VRs
44+
-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"
45+
printf "$usage_content" "$(basename $0)" >&2
2746
}
2847

2948

@@ -40,10 +59,14 @@ maxthreads=10
4059
LOGFILE=cloud.log
4160
zone=""
4261
inzone=""
62+
vmids=""
63+
vmidsclause=""
64+
withids=""
65+
vmtable="vm_instance"
4366

4467

4568

46-
while getopts 'sarhnvd:m:u:p:t:l:z:' OPTION
69+
while getopts 'sarhnvd:m:u:p:t:l:z:i:j:' OPTION
4770
do
4871
case $OPTION in
4972
s) system=1
@@ -72,21 +95,36 @@ do
7295
;;
7396
z) zone=" AND data_center_id=""$OPTARG"
7497
inzone=" in zone id=""$OPTARG"
98+
;;
99+
i) vmids="$OPTARG"
100+
withids=" with id=""$OPTARG"
101+
;;
102+
j) vmtable="$OPTARG"
75103
esac
76104
done
77105

78106

79-
107+
prepare_ids_clause() {
108+
if [[ ! -z "$vmidsclause" ]]; then
109+
return
110+
fi
111+
vmidsclause=""
112+
if [[ ! -z "$vmids" ]]; then
113+
vmidsclause=" AND uuid IN ('$vmids')"
114+
vmidsclause=${vmidsclause/,/"','"}
115+
fi
116+
}
80117

81118
stop_start_system() {
82-
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"`)
83-
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"`)
119+
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"`)
84122
length_secondary=(${#secondary[@]})
85123
length_console=(${#console[@]})
86124

87125

88-
echo -e "\nStopping and starting $length_secondary secondary storage vm(s)$inzone..."
89-
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_secondary secondary storage vm(s)$inzone..." >>$LOGFILE
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
90128

91129
for d in "${secondary[@]}"; do
92130
echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping secondary storage vm with id $d" >>$LOGFILE
@@ -107,12 +145,12 @@ done
107145
if [ "$length_secondary" == "0" ];then
108146
echo -e "No running secondary storage vms found \n"
109147
else
110-
echo -e "Done stopping and starting secondary storage vm(s)$inzone"
111-
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting secondary storage vm(s)$inzone." >>$LOGFILE
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
112150
fi
113151

114-
echo -e "\nStopping and starting $length_console console proxy vm(s)$inzone..."
115-
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_console console proxy vm(s)$inzone..." >>$LOGFILE
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
116154

117155
for d in "${console[@]}"; do
118156
echo "[$(date "+%Y.%m.%d-%H.%M.%S")] INFO: Stopping console proxy with id $d" >>$LOGFILE
@@ -133,17 +171,18 @@ done
133171
if [ "$length_console" == "0" ];then
134172
echo -e "No running console proxy vms found \n"
135173
else
136-
echo "Done stopping and starting console proxy vm(s) $inzone."
137-
echo "[$(date "+%Y.%m.%d-%H.%M.%S")] Done stopping and starting console proxy vm(s) $inzone." >>$LOGFILE
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
138176
fi
139177
}
140178

141179
stop_start_router() {
142-
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"`)
180+
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"`)
143182
length_router=(${#router[@]})
144183

145-
echo -e "\nStopping and starting $length_router running routing vm(s)$inzone... "
146-
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Stopping and starting $length_router running routing vm(s)$inzone... " >>$LOGFILE
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
147186

148187
#Spawn reboot router in parallel - run commands in <n> chunks - number of threads is configurable
149188

@@ -194,8 +233,8 @@ stop_start_router() {
194233
sleep 10
195234
done
196235

197-
echo -e "Done restarting router(s)$inzone. \n"
198-
echo -e "[$(date "+%Y.%m.%d-%H.%M.%S")] Done restarting router(s)$inzone. \n" >>$LOGFILE
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
199238

200239
fi
201240
}

0 commit comments

Comments
 (0)