First stab at persisting lxc customizations on config file instead of using lxc-start "-s" parameter
This commit is contained in:
parent
251fe68035
commit
5f102d3e10
3 changed files with 34 additions and 3 deletions
|
@ -72,9 +72,11 @@ module Vagrant
|
||||||
if ENV['LXC_START_LOG_FILE']
|
if ENV['LXC_START_LOG_FILE']
|
||||||
extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG']
|
extra = ['-o', ENV['LXC_START_LOG_FILE'], '-l', 'DEBUG']
|
||||||
end
|
end
|
||||||
customizations = customizations + @customizations
|
|
||||||
|
|
||||||
@cli.transition_to(:running) { |c| c.start(customizations, (extra || nil)) }
|
prune_customizations
|
||||||
|
write_customizations(customizations + @customizations)
|
||||||
|
|
||||||
|
@cli.transition_to(:running) { |c| c.start([], (extra || nil)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def forced_halt
|
def forced_halt
|
||||||
|
@ -121,8 +123,27 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prune_customizations
|
||||||
|
# Use sed to just strip out the block of code which was inserted
|
||||||
|
# by Vagrant
|
||||||
|
@logger.debug 'Prunning vagrant-lxc customizations'
|
||||||
|
@sudo_wrapper.su_c("sed -e '/^# VAGRANT-BEGIN/,/^# VAGRANT-END/ d' -ibak #{base_path.join('config')}")
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def write_customizations(customizations)
|
||||||
|
customizations = customizations.map do |key, value|
|
||||||
|
"lxc.#{key}=#{value}"
|
||||||
|
end
|
||||||
|
customizations.unshift '# VAGRANT-BEGIN'
|
||||||
|
customizations << '# VAGRANT-END'
|
||||||
|
|
||||||
|
config_file = base_path.join('config').to_s
|
||||||
|
customizations.each do |line|
|
||||||
|
@sudo_wrapper.su_c("echo '#{line}' >> #{config_file}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def import_template(path)
|
def import_template(path)
|
||||||
template_name = "vagrant-tmp-#{@container_name}"
|
template_name = "vagrant-tmp-#{@container_name}"
|
||||||
|
|
|
@ -64,7 +64,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def start(overrides = [], extra_opts = [])
|
def start(overrides = [], extra_opts = [])
|
||||||
options = overrides.map { |key, value| ["-s", "lxc.#{key}='#{value}'"] }.flatten
|
options = []
|
||||||
options += extra_opts if extra_opts
|
options += extra_opts if extra_opts
|
||||||
run :start, '-d', '--name', @name, *options
|
run :start, '-d', '--name', @name, *options
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,16 @@ module Vagrant
|
||||||
execute *(['sudo'] + command)
|
execute *(['sudo'] + command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def su_c(command)
|
||||||
|
su_command = if @wrapper_path
|
||||||
|
"#{@wrapper_path} \"#{command}\""
|
||||||
|
else
|
||||||
|
"su root -c \"#{command}\""
|
||||||
|
end
|
||||||
|
@logger.debug "Running 'sudo #{su_command}'"
|
||||||
|
system "sudo #{su_command}"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# TODO: Review code below this line, it was pretty much a copy and
|
# TODO: Review code below this line, it was pretty much a copy and
|
||||||
|
|
Loading…
Reference in a new issue