diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index 8281cf3..e4dee2d 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -53,6 +53,7 @@ module Vagrant b.use ForwardPorts b.use SaneDefaults b.use Customize + b.use AfterCreate b.use Boot end end @@ -86,7 +87,6 @@ module Vagrant end end b.use action_start - b.use AfterCreate # b.use Vagrant::Action::Builtin::SetHostname end end diff --git a/lib/vagrant-lxc/action/after_create.rb b/lib/vagrant-lxc/action/after_create.rb index 866e9ea..1e12ebc 100644 --- a/lib/vagrant-lxc/action/after_create.rb +++ b/lib/vagrant-lxc/action/after_create.rb @@ -3,10 +3,11 @@ module Vagrant module Action class AfterCreate < BaseAction def call(env) + # Continue, we need the VM to be booted. + @app.call env if env[:just_created] && (script = env[:machine].box.metadata['after-create-script']) env[:machine].provider.container.run_after_create_script script end - @app.call env end end end diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 3509549..5c9b425 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -1,10 +1,19 @@ module Vagrant module LXC module Action + # DISCUSS: The Boot action has a different meaning on VB provider and it + # assumes the machine has been started already. class Boot < BaseAction def call(env) config = env[:machine].provider_config - env[:machine].provider.container.start(config) + + # Allows this middleware to be called multiple times. We need to + # support this as base boxes might have after create scripts which + # require SSH access + unless env[:machine].state.running? + env[:machine].provider.container.start(config) + end + @app.call env end end