Sha256: 7e8540dad6485146c2ab497d5337126c07fea741b1d06cc285fcfe93c85f1898

Contents?: true

Size: 1.56 KB

Versions: 59

Compression:

Stored size: 1.56 KB

Contents

require "thread"

require "log4r"

module VagrantPlugins
  module DockerProvider
    module Action
      class WaitForRunning
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::docker::waitforrunning")
        end

        def call(env)
          machine = env[:machine]

          wait = true
          if !machine.provider_config.remains_running
            wait = false
          elsif machine.provider.state.id == :running
            wait = false
          end

          # If we're not waiting, just return
          return @app.call(env) if !wait

          machine.ui.output(I18n.t("docker_provider.waiting_for_running"))

          # First, make sure it leaves the stopped state if its supposed to.
          after = sleeper(5)
          while machine.provider.state.id == :stopped
            if after[:done]
              raise Errors::StateStopped
            end
            sleep 0.2
          end

          # Then, wait for it to become running
          after = sleeper(30)
          while true
            state = machine.provider.state
            break if state.id == :running
            @logger.info("Waiting for container to run. State: #{state.id}")

            if after[:done]
              raise Errors::StateNotRunning
            end

            sleep 0.2
          end

          @app.call(env)
        end

        protected

        def sleeper(duration)
          Thread.new(duration) do |d|
            sleep(d)
            Thread.current[:done] = true
          end
        end
      end
    end
  end
end

Version data entries

59 entries across 52 versions & 7 rubygems

Version Path
vagrant-unbundled-2.2.19.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.18.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.16.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.14.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.10.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.9.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.8.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.7.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.6.2 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.6.1 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.6.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.5.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.4.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.3.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.2.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.2.0.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.1.4.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.1.2.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/docker/action/wait_for_running.rb