From 270cbd8a51942c4489b9ea6042c6c7e594f040ef Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Mon, 11 Mar 2013 00:08:28 -0300 Subject: [PATCH] Move forced halt code into its own action --- lib/vagrant-lxc/action.rb | 6 ++---- lib/vagrant-lxc/action/forced_halt.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 lib/vagrant-lxc/action/forced_halt.rb 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