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]
- 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 `--restart` instead of `-r` on daemon [GH-4477]
- provisioners/file: validation of source is relative to Vagrantfile [GH-5252]
- pushes/atlas: send additional box metadata [GH-5283]
- 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 << "-d " if config[:daemonize]
args << "--name #{name} " if name && config[:auto_assign_name]
args << "--restart=#{config[:restart]}" if config[:restart]
args << config[:args] if config[:args]
@machine.communicate.sudo %[
rm -f #{config[:cidfile]}
@ -105,18 +106,15 @@ module VagrantPlugins
# recent versions use the full container ID
# See https://github.com/dotcloud/docker/pull/2140 for more information
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
protected
# This handles outputting the communication data back to the UI
def handle_comm(type, data)
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
data = data.chomp
return if data.empty?

View File

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

View File

@ -24,13 +24,6 @@ module VagrantPlugins
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)
@machine.guest.capability(:docker_configure_vagrant_user)
end

View File

@ -19,11 +19,6 @@ module VagrantPlugins
Cap::Debian::DockerInstall
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
require_relative "cap/debian/docker_start_service"
Cap::Debian::DockerStartService
@ -34,11 +29,6 @@ module VagrantPlugins
Cap::Redhat::DockerInstall
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
require_relative "cap/redhat/docker_start_service"
Cap::Redhat::DockerStartService

View File

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