provisioners/docker: support restart flag [GH-4477]

This commit is contained in:
Mitchell Hashimoto 2015-07-07 12:17:24 -06:00
parent 9516427136
commit 9c7f666e48
8 changed files with 10 additions and 69 deletions

View File

@ -108,6 +108,7 @@ BUG FIXES:
`which` since that doesn't exist on some systems. [GH-5170] `which` since that doesn't exist on some systems. [GH-5170]
- provisioners/chef-zero: support more chef-zero/local mode attributes [GH-5339] - provisioners/chef-zero: support more chef-zero/local mode attributes [GH-5339]
- provisioners/docker: use docker.com instead of docker.io [GH-5216] - provisioners/docker: use docker.com instead of docker.io [GH-5216]
- provisioners/docker: use `--restart` instead of `-r` on daemon [GH-4477]
- provisioners/file: validation of source is relative to Vagrantfile [GH-5252] - provisioners/file: validation of source is relative to Vagrantfile [GH-5252]
- pushes/atlas: send additional box metadata [GH-5283] - pushes/atlas: send additional box metadata [GH-5283]
- pushes/local-exec: fix "text file busy" error for inline [GH-5695] - pushes/local-exec: fix "text file busy" error for inline [GH-5695]

View File

@ -1,32 +0,0 @@
module VagrantPlugins
module DockerProvisioner
module Cap
module Debian
module DockerConfigureAutoStart
def self.docker_configure_auto_start(machine)
machine.communicate.tap do |comm|
if !comm.test('grep -q \'\-r=true\' /etc/default/docker')
comm.sudo("echo 'DOCKER_OPTS=\"-r=true ${DOCKER_OPTS}\"' >> /etc/default/docker")
comm.sudo("service docker restart")
# Wait some amount time for the pid to become available
# so that we don't start executing Docker commands until
# it is available.
if machine.guest.capability?(:docker_daemon_running)
[0, 1, 2, 4].each do |delay|
sleep delay
break if machine.guest.capability(:docker_daemon_running)
end
else
# This OS doesn't support checking if Docker is running,
# so just wait 5 seconds.
sleep 5
end
end
end
end
end
end
end
end
end

View File

@ -1,15 +0,0 @@
module VagrantPlugins
module DockerProvisioner
module Cap
module Redhat
module DockerConfigureAutoStart
def self.docker_configure_auto_start(machine)
if ! machine.communicate.test('grep -q \'\-r=true\' /etc/sysconfig/docker')
machine.communicate.sudo("sed -i.bak 's/docker -d/docker -d -r=true/' /etc/sysconfig/docker ")
end
end
end
end
end
end
end

View File

@ -90,6 +90,7 @@ module VagrantPlugins
args = "--cidfile=#{config[:cidfile]} " args = "--cidfile=#{config[:cidfile]} "
args << "-d " if config[:daemonize] args << "-d " if config[:daemonize]
args << "--name #{name} " if name && config[:auto_assign_name] args << "--name #{name} " if name && config[:auto_assign_name]
args << "--restart=#{config[:restart]}" if config[:restart]
args << config[:args] if config[:args] args << config[:args] if config[:args]
@machine.communicate.sudo %[ @machine.communicate.sudo %[
rm -f #{config[:cidfile]} rm -f #{config[:cidfile]}
@ -105,18 +106,15 @@ module VagrantPlugins
# recent versions use the full container ID # recent versions use the full container ID
# See https://github.com/dotcloud/docker/pull/2140 for more information # See https://github.com/dotcloud/docker/pull/2140 for more information
return comm.test("#{docker_ps} | grep -wFq #{id}") || return comm.test("#{docker_ps} | grep -wFq #{id}") ||
comm.test("#{docker_ps} -notrunc | grep -wFq #{id}") comm.test("#{docker_ps} -notrunc | grep -wFq #{id}")
end end
end end
protected protected
# This handles outputting the communication data back to the UI # This handles outputting the communication data back to the UI
def handle_comm(type, data) def handle_comm(type, data)
if [:stderr, :stdout].include?(type) if [:stderr, :stdout].include?(type)
# Output the data with the proper color based on the stream.
color = type == :stdout ? :green : :red
# Clear out the newline since we add one # Clear out the newline since we add one
data = data.chomp data = data.chomp
return if data.empty? return if data.empty?

View File

@ -72,6 +72,7 @@ module VagrantPlugins
params[:image] ||= name params[:image] ||= name
params[:auto_assign_name] = true if !params.key?(:auto_assign_name) params[:auto_assign_name] = true if !params.key?(:auto_assign_name)
params[:daemonize] = true if !params.key?(:daemonize) params[:daemonize] = true if !params.key?(:daemonize)
params[:restart] = "always" if !params.key?(:restart)
end end
end end
end end

View File

@ -24,13 +24,6 @@ module VagrantPlugins
end end
end end
if @machine.guest.capability?(:docker_configure_auto_start)
@machine.ui.detail(I18n.t("vagrant.docker_configure_autostart"))
@machine.guest.capability(:docker_configure_auto_start)
else
@machine.env.ui.warn I18n.t('vagrant.docker_auto_start_not_available')
end
if @machine.guest.capability?(:docker_configure_vagrant_user) if @machine.guest.capability?(:docker_configure_vagrant_user)
@machine.guest.capability(:docker_configure_vagrant_user) @machine.guest.capability(:docker_configure_vagrant_user)
end end

View File

@ -19,11 +19,6 @@ module VagrantPlugins
Cap::Debian::DockerInstall Cap::Debian::DockerInstall
end end
guest_capability("debian", "docker_configure_auto_start") do
require_relative "cap/debian/docker_configure_auto_start"
Cap::Debian::DockerConfigureAutoStart
end
guest_capability("debian", "docker_start_service") do guest_capability("debian", "docker_start_service") do
require_relative "cap/debian/docker_start_service" require_relative "cap/debian/docker_start_service"
Cap::Debian::DockerStartService Cap::Debian::DockerStartService
@ -34,11 +29,6 @@ module VagrantPlugins
Cap::Redhat::DockerInstall Cap::Redhat::DockerInstall
end end
guest_capability("redhat", "docker_configure_auto_start") do
require_relative "cap/redhat/docker_configure_auto_start"
Cap::Redhat::DockerConfigureAutoStart
end
guest_capability("redhat", "docker_start_service") do guest_capability("redhat", "docker_start_service") do
require_relative "cap/redhat/docker_start_service" require_relative "cap/redhat/docker_start_service"
Cap::Redhat::DockerStartService Cap::Redhat::DockerStartService

View File

@ -59,11 +59,13 @@ describe VagrantPlugins::DockerProvisioner::Config do
auto_assign_name: true, auto_assign_name: true,
image: "foo", image: "foo",
daemonize: false, daemonize: false,
restart: "always",
}) })
expect(cs["bar"]).to eq({ expect(cs["bar"]).to eq({
auto_assign_name: true, auto_assign_name: true,
image: "bar", image: "bar",
daemonize: true, daemonize: true,
restart: "always",
}) })
end end
@ -102,6 +104,7 @@ describe VagrantPlugins::DockerProvisioner::Config do
auto_assign_name: true, auto_assign_name: true,
daemonize: true, daemonize: true,
image: "foo", image: "foo",
restart: "always",
} }
}) })
end end
@ -115,6 +118,7 @@ describe VagrantPlugins::DockerProvisioner::Config do
auto_assign_name: false, auto_assign_name: false,
daemonize: true, daemonize: true,
image: "foo", image: "foo",
restart: "always",
} }
}) })
end end
@ -128,6 +132,7 @@ describe VagrantPlugins::DockerProvisioner::Config do
auto_assign_name: true, auto_assign_name: true,
daemonize: false, daemonize: false,
image: "foo", image: "foo",
restart: "always",
} }
}) })
end end