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-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/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
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/docker/action/wait_for_running.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/docker/action/wait_for_running.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.1.1.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.0.4.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.0.3.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.0.2.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.0.1.0 plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-2.0.0.1 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-1.9.8.1 plugins/providers/docker/action/wait_for_running.rb
vagrant-unbundled-1.9.7.1 plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/docker/action/wait_for_running.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/docker/action/wait_for_running.rb