Sha256: c0e3798a4a80f2b7dcdff439f477a1496f496fc7f770d8a612f3737662356889

Contents?: true

Size: 998 Bytes

Versions: 2

Compression:

Stored size: 998 Bytes

Contents

module VagrantPlugins
  module Ventriloquist
    class Service
      CONTAINER_IDS_PATH = '/var/lib/ventriloquist/cids'

      attr_reader :name, :config, :docker_client

      def initialize(name, config, docker_client)
        @name, @config, @docker_client = name, config, docker_client
      end

      def provision(machine)
        cidfile = "#{CONTAINER_IDS_PATH}/#{@name}"

        if @docker_client.container_running?("$(cat #{cidfile})")
          machine.env.ui.info("Service '#{@name}' already running")
        else
          machine.env.ui.info("Starting '#{@name}' service")
          machine.communicate.sudo("mkdir -p #{CONTAINER_IDS_PATH}")
          # Reduce network latency, see https://groups.google.com/d/msg/docker-user/Z3zQuRawIsE/2AEkl30WpTQJ
          # for more info
          @config[:dns]     = '127.0.0.1'
          @config[:name]    = @name
          @config[:cidfile] = cidfile
          @docker_client.run_container(@config)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ventriloquist-0.4.1 lib/ventriloquist/service.rb
ventriloquist-0.4.0 lib/ventriloquist/service.rb