Fix handling of non-fatal lxc-stop return code

Fixes #405
This commit is contained in:
Robert Heinzmann 2016-02-16 12:13:53 +01:00 committed by Cam Cope
parent aa5fb7a932
commit 544c061e65
3 changed files with 15 additions and 3 deletions

View file

@ -85,9 +85,20 @@ module Vagrant
run :start, '-d', '--name', @name, *Array(options)
end
## lxc-stop will exit 2 if machine was already stopped
# Man Page:
# 2 The specified container exists but was not running.
def stop
attach '/sbin/halt' if supports_attach?
begin
run :stop, '--name', @name
rescue LXC::Errors::ExecuteError => e
if e.exitcode == 2
@logger.debug "Machine already stopped, lxc-stop returned 2"
else
raise e
end
end
end
def attach(*cmd)

View file

@ -5,12 +5,13 @@ module Vagrant
module Errors
class ExecuteError < Vagrant::Errors::VagrantError
error_key(:lxc_execute_error)
attr_reader :stderr, :stdout
attr_reader :stderr, :stdout, :exitcode
def initialize(message, *args)
super
if message.is_a?(Hash)
@stderr = message[:stderr]
@stdout = message[:stdout]
@exitcode = message[:exitcode]
end
end
end

View file

@ -49,7 +49,7 @@ module Vagrant
@logger.info("Exit code != 0, but interrupted. Ignoring.")
else
raise LXC::Errors::ExecuteError,
command: command.inspect, stderr: r.stderr, stdout: r.stdout
command: command.inspect, stderr: r.stderr, stdout: r.stdout, exitcode: r.exit_code
end
end
end