Skip to content

Commit ba009ed

Browse files
lsimonsyadvr
authored andcommitted
CLOUDSTACK-7143: attempt to be safer when cleaning up
1 parent e43e083 commit ba009ed

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

tools/appliance/build.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function stop_vbox() {
276276

277277
function clean_vbox() {
278278
log INFO "deleting all virtualbox vms and disks for ${USER}"
279-
bundle exec ./vbox_vm_clean.rb --delete
279+
bundle exec ./vbox_vm_clean.rb --delete --kill
280280
bundle exec ./vbox_disk_clean.rb
281281
}
282282

@@ -502,18 +502,17 @@ function hyperv_export() {
502502
function main() {
503503
prepare
504504
if [ "${clean_vbox}" == "1" ]; then
505-
clean_vbox --delete
506-
add_on_exit clean_vbox --delete
505+
clean_vbox
506+
add_on_exit clean_vbox
507507
else
508-
stop_vbox # some extra encouragement for virtualbox to stop things
508+
stop_vbox
509509
fi
510510
create_definition
511511
veewee_destroy # in case of left-over cruft from failed build
512512
add_on_exit veewee_destroy
513513
veewee_build
514514
save_mac_address
515515
veewee_halt
516-
stop_vbox # some extra encouragement for virtualbox to stop things
517516
retry 10 check_appliance_shutdown
518517
retry 10 check_appliance_disk_ready
519518
retry 10 remove_shares

tools/appliance/vbox_vm_clean.rb

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
include Sys
99

1010
do_delete = (ARGV.include? 'delete' or ARGV.include? '--delete' or ARGV.include? '-d')
11+
do_kill = (ARGV.include? 'kill' or ARGV.include? '--kill' or ARGV.include? '-k')
1112

1213
lines = `VBoxManage list vms`
1314
vms = lines.split(/\n/)
@@ -26,29 +27,31 @@
2627
`#{cmd}`
2728
end
2829

29-
sleep(1)
30-
# ps x | grep VBoxHeadless | grep systemvm64template-4.4.0 | egrep -o '^\s*[0-9]+' | xargs kill
31-
ProcTable.ps { |p|
32-
next unless p.cmdline.include? "VBoxHeadless"
33-
next unless p.cmdline.include? vm_name
34-
# not all rubies / proctables expose ruid
35-
if defined? p.ruid
36-
# VBoxManage should only list _our_ vms, but just to be safe...
37-
next unless p.ruid == Process.uid
38-
end
39-
40-
puts "kill -SIGKILL #{p.pid}"
41-
begin
42-
Process.kill("KILL", p.pid)
43-
rescue => exception
44-
puts exception.backtrace
45-
end
46-
sleep(5)
47-
puts "kill -SIGTERM #{p.pid}"
48-
begin
49-
Process.kill("TERM", p.pid)
50-
rescue => exception
51-
puts exception.backtrace
30+
if do_kill
31+
sleep(1)
32+
# ps x | grep VBoxHeadless | grep systemvm64template-4.4.0 | egrep -o '^\s*[0-9]+' | xargs kill
33+
ProcTable.ps do |p|
34+
next unless p.cmdline.include? "VBoxHeadless"
35+
next unless p.cmdline.include? vm_name
36+
# not all rubies / proctables expose ruid
37+
if defined? p.ruid
38+
# VBoxManage should only list _our_ vms, but just to be safe...
39+
next unless p.ruid == Process.uid
40+
end
41+
42+
puts "kill -SIGKILL #{p.pid}"
43+
begin
44+
Process.kill("KILL", p.pid)
45+
rescue => exception
46+
puts exception.backtrace
47+
end
48+
sleep(5)
49+
puts "kill -SIGTERM #{p.pid}"
50+
begin
51+
Process.kill("TERM", p.pid)
52+
rescue => exception
53+
puts exception.backtrace
54+
end
5255
end
53-
}
56+
end
5457
end

0 commit comments

Comments
 (0)