mirror of https://github.com/apache/cloudstack.git
bug 7210: created cloud-sysvmadm script that stops/starts Running system vms.
status 7210: resolved fixed
This commit is contained in:
parent
3b7af7e35b
commit
65e05f4922
|
|
@ -560,6 +560,7 @@ fi
|
|||
%attr(0755,root,root) %{_bindir}/%{name}-migrate-databases
|
||||
%attr(0755,root,root) %{_bindir}/%{name}-migrate-snapshot
|
||||
%attr(0755,root,root) %{_bindir}/%{name}-check-snapshot
|
||||
%attr(0755,root,root) %{_bindir}/%{name}-sysvmadm
|
||||
%dir %{_datadir}/%{name}/setup
|
||||
%{_datadir}/%{name}/setup/create-database.sql
|
||||
%{_datadir}/%{name}/setup/create-index-fk.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,160 @@
|
|||
#!/bin/bash
|
||||
|
||||
. /etc/rc.d/init.d/functions
|
||||
|
||||
#set -x
|
||||
|
||||
usage() {
|
||||
printf "\nUsage: %s: [-d] [-u] [-p] [-s] [-r] [-a] \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 -s - stop then start any running SSVM or console proxy in any
|
||||
zone \n -r - stop then start any running virtual router in any zone \n -a - stop then start any running SSVM, console proxy, or virtual router in any zone\n" $(basename $0) >&2
|
||||
}
|
||||
|
||||
|
||||
system=
|
||||
router=
|
||||
all=
|
||||
db=localhost
|
||||
user=root
|
||||
password=
|
||||
|
||||
|
||||
while getopts 'sard:u:p:' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
s) system=1
|
||||
;;
|
||||
r) router=1
|
||||
;;
|
||||
a) all=1
|
||||
;;
|
||||
d) db="$OPTARG"
|
||||
;;
|
||||
u) user="$OPTARG"
|
||||
;;
|
||||
p) password="$OPTARG"
|
||||
;;
|
||||
?) usage
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
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\""`)
|
||||
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\""`)
|
||||
length_secondary=(${#secondary[@]})
|
||||
length_console=(${#console[@]})
|
||||
|
||||
|
||||
echo -e "\nStopping and starting secondary storage vms..."
|
||||
for d in "${secondary[@]}"; do
|
||||
jobresult=$(send_request stopSystemVm $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to stop secondary storage vm with id $d"
|
||||
else
|
||||
jobresult=$(send_request startSystemVm $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to start secondary storage vm with id $d"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$length_secondary" == "0" ];then
|
||||
echo -e "No running secondary storage vms found \n"
|
||||
else
|
||||
echo -e "Done \n"
|
||||
fi
|
||||
|
||||
echo "Stopping and starting console proxy vms..."
|
||||
for d in "${console[@]}"; do
|
||||
jobresult=$(send_request stopSystemVm $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to stop console proxy vm with id $d"
|
||||
else
|
||||
jobresult=$(send_request startSystemVm $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to start console proxy vm with id $d"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$length_console" == "0" ];then
|
||||
echo -e "No running console proxy vms found \n"
|
||||
else
|
||||
echo -e "Done \n"
|
||||
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\""`)
|
||||
length_router=(${#router[@]})
|
||||
|
||||
echo -e "\nStopping and starting running routing vms..."
|
||||
for d in "${router[@]}"; do
|
||||
jobresult=$(send_request stopRouter $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to stop domain router with id $d"
|
||||
else
|
||||
jobresult=$(send_request startRouter $d)
|
||||
if [ "$jobresult" != "1" ]; then
|
||||
echo "ERROR: Failed to start domain router with id $d"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$length_router" == "0" ];then
|
||||
echo -e "No running router vms found \n"
|
||||
else
|
||||
echo -e "Done \n"
|
||||
fi
|
||||
}
|
||||
|
||||
stop_start_all() {
|
||||
stop_start_system
|
||||
stop_start_router
|
||||
}
|
||||
|
||||
send_request(){
|
||||
jobid=`curl -sS "http://localhost:8096/?command=$1&id=$2&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F: {'print $3'}`
|
||||
if [ "$jobid" == "" ]; then
|
||||
echo 2
|
||||
return
|
||||
fi
|
||||
jobresult=$(query_async_job_result $jobid)
|
||||
echo $jobresult
|
||||
}
|
||||
|
||||
query_async_job_result() {
|
||||
while [ 1 ]
|
||||
do
|
||||
jobstatus=`curl -sS "http://localhost:8096/?command=queryAsyncJobResult&jobId=$1&response=json" | sed 's/\"//g' | sed 's/ //g' | sed 's/{//g' | sed 's/}//g' | awk -F, {'print $2'} | awk -F: {'print $2'}`
|
||||
if [ "$jobstatus" != "0" ]; then
|
||||
echo $jobstatus
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
}
|
||||
|
||||
if [ "$system$router$all" == "" ]
|
||||
then
|
||||
usage
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
if [ "$all" == "1" ]
|
||||
then
|
||||
stop_start_all
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$system" == "1" ]
|
||||
then
|
||||
stop_start_system
|
||||
fi
|
||||
|
||||
if [ "$router" == "1" ]
|
||||
then
|
||||
stop_start_router
|
||||
fi
|
||||
Loading…
Reference in New Issue