mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-7143: attempt to be safer when cleaning up
This commit is contained in:
parent
e43e083893
commit
ba009ed51a
|
|
@ -276,7 +276,7 @@ function stop_vbox() {
|
|||
|
||||
function clean_vbox() {
|
||||
log INFO "deleting all virtualbox vms and disks for ${USER}"
|
||||
bundle exec ./vbox_vm_clean.rb --delete
|
||||
bundle exec ./vbox_vm_clean.rb --delete --kill
|
||||
bundle exec ./vbox_disk_clean.rb
|
||||
}
|
||||
|
||||
|
|
@ -502,10 +502,10 @@ function hyperv_export() {
|
|||
function main() {
|
||||
prepare
|
||||
if [ "${clean_vbox}" == "1" ]; then
|
||||
clean_vbox --delete
|
||||
add_on_exit clean_vbox --delete
|
||||
clean_vbox
|
||||
add_on_exit clean_vbox
|
||||
else
|
||||
stop_vbox # some extra encouragement for virtualbox to stop things
|
||||
stop_vbox
|
||||
fi
|
||||
create_definition
|
||||
veewee_destroy # in case of left-over cruft from failed build
|
||||
|
|
@ -513,7 +513,6 @@ function main() {
|
|||
veewee_build
|
||||
save_mac_address
|
||||
veewee_halt
|
||||
stop_vbox # some extra encouragement for virtualbox to stop things
|
||||
retry 10 check_appliance_shutdown
|
||||
retry 10 check_appliance_disk_ready
|
||||
retry 10 remove_shares
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ require 'sys/proctable'
|
|||
include Sys
|
||||
|
||||
do_delete = (ARGV.include? 'delete' or ARGV.include? '--delete' or ARGV.include? '-d')
|
||||
do_kill = (ARGV.include? 'kill' or ARGV.include? '--kill' or ARGV.include? '-k')
|
||||
|
||||
lines = `VBoxManage list vms`
|
||||
vms = lines.split(/\n/)
|
||||
|
|
@ -26,29 +27,31 @@ vms.each do |vmline|
|
|||
`#{cmd}`
|
||||
end
|
||||
|
||||
sleep(1)
|
||||
# ps x | grep VBoxHeadless | grep systemvm64template-4.4.0 | egrep -o '^\s*[0-9]+' | xargs kill
|
||||
ProcTable.ps { |p|
|
||||
next unless p.cmdline.include? "VBoxHeadless"
|
||||
next unless p.cmdline.include? vm_name
|
||||
# not all rubies / proctables expose ruid
|
||||
if defined? p.ruid
|
||||
# VBoxManage should only list _our_ vms, but just to be safe...
|
||||
next unless p.ruid == Process.uid
|
||||
end
|
||||
if do_kill
|
||||
sleep(1)
|
||||
# ps x | grep VBoxHeadless | grep systemvm64template-4.4.0 | egrep -o '^\s*[0-9]+' | xargs kill
|
||||
ProcTable.ps do |p|
|
||||
next unless p.cmdline.include? "VBoxHeadless"
|
||||
next unless p.cmdline.include? vm_name
|
||||
# not all rubies / proctables expose ruid
|
||||
if defined? p.ruid
|
||||
# VBoxManage should only list _our_ vms, but just to be safe...
|
||||
next unless p.ruid == Process.uid
|
||||
end
|
||||
|
||||
puts "kill -SIGKILL #{p.pid}"
|
||||
begin
|
||||
Process.kill("KILL", p.pid)
|
||||
rescue => exception
|
||||
puts exception.backtrace
|
||||
puts "kill -SIGKILL #{p.pid}"
|
||||
begin
|
||||
Process.kill("KILL", p.pid)
|
||||
rescue => exception
|
||||
puts exception.backtrace
|
||||
end
|
||||
sleep(5)
|
||||
puts "kill -SIGTERM #{p.pid}"
|
||||
begin
|
||||
Process.kill("TERM", p.pid)
|
||||
rescue => exception
|
||||
puts exception.backtrace
|
||||
end
|
||||
end
|
||||
sleep(5)
|
||||
puts "kill -SIGTERM #{p.pid}"
|
||||
begin
|
||||
Process.kill("TERM", p.pid)
|
||||
rescue => exception
|
||||
puts exception.backtrace
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue