diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index fecd285..3127512 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -6,6 +6,7 @@ require 'vagrant-lxc/action/check_running' require 'vagrant-lxc/action/create' require 'vagrant-lxc/action/created' require 'vagrant-lxc/action/destroy' +require 'vagrant-lxc/action/forced_halt' require 'vagrant-lxc/action/handle_box_metadata' require 'vagrant-lxc/action/is_running' require 'vagrant-lxc/action/network' @@ -124,10 +125,7 @@ module Vagrant if env[:result] b2.use Vagrant::Action::Builtin::Call, Vagrant::Action::Builtin::GracefulHalt, :stopped, :running do |env2, b3| if !env2[:result] && env2[:machine].provider.state.running? - # TODO: Container#halt is kinda graceful as well, if it doesn't - # or we can issue a lxc-stop. Might as well be handled by the - # container itself, who knows, we just need to handle it :P - env2[:machine].provider.container.halt + b3.use ForcedHalt end end else diff --git a/lib/vagrant-lxc/action/forced_halt.rb b/lib/vagrant-lxc/action/forced_halt.rb new file mode 100644 index 0000000..2c2961f --- /dev/null +++ b/lib/vagrant-lxc/action/forced_halt.rb @@ -0,0 +1,22 @@ +module Vagrant + module LXC + module Action + class ForcedHalt + def initialize(app, env) + @app = app + end + + def call(env) + if env[:machine].provider.state.running? + env[:ui].info I18n.t("vagrant.actions.vm.halt.force") + # TODO: Container#halt is kinda graceful as well, if it doesn't + # work we can issue a lxc-stop. + env[:machine].provider.container.halt + end + + @app.call(env) + end + end + end + end +end