diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d7a2c68e..a8f854210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/plugins/provisioners/docker/cap/debian/docker_configure_auto_start.rb b/plugins/provisioners/docker/cap/debian/docker_configure_auto_start.rb deleted file mode 100644 index 32a8defd2..000000000 --- a/plugins/provisioners/docker/cap/debian/docker_configure_auto_start.rb +++ /dev/null @@ -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 diff --git a/plugins/provisioners/docker/cap/redhat/docker_configure_auto_start.rb b/plugins/provisioners/docker/cap/redhat/docker_configure_auto_start.rb deleted file mode 100644 index aaae9d787..000000000 --- a/plugins/provisioners/docker/cap/redhat/docker_configure_auto_start.rb +++ /dev/null @@ -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 diff --git a/plugins/provisioners/docker/client.rb b/plugins/provisioners/docker/client.rb index 6ea699056..93d755e6f 100644 --- a/plugins/provisioners/docker/client.rb +++ b/plugins/provisioners/docker/client.rb @@ -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? diff --git a/plugins/provisioners/docker/config.rb b/plugins/provisioners/docker/config.rb index 7e6c37787..bcf4cf672 100644 --- a/plugins/provisioners/docker/config.rb +++ b/plugins/provisioners/docker/config.rb @@ -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 diff --git a/plugins/provisioners/docker/installer.rb b/plugins/provisioners/docker/installer.rb index 01028f5c0..cfcebdd43 100644 --- a/plugins/provisioners/docker/installer.rb +++ b/plugins/provisioners/docker/installer.rb @@ -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 diff --git a/plugins/provisioners/docker/plugin.rb b/plugins/provisioners/docker/plugin.rb index c68e772e1..b606729ac 100644 --- a/plugins/provisioners/docker/plugin.rb +++ b/plugins/provisioners/docker/plugin.rb @@ -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 diff --git a/test/unit/plugins/provisioners/docker/config_test.rb b/test/unit/plugins/provisioners/docker/config_test.rb index e34c24bba..e12f883c4 100644 --- a/test/unit/plugins/provisioners/docker/config_test.rb +++ b/test/unit/plugins/provisioners/docker/config_test.rb @@ -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