Sha256: 4945339072a1406270dd288c9585d643f5a5d33722323da6032db59a9bfb9330

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

module Percheron
  module Actions
    class Start

      include Base

      def initialize(container, dependant_containers: [], cmd: false, exec_scripts: true)
        @container = container
        @dependant_containers = dependant_containers
        @cmd = cmd
        @exec_scripts = exec_scripts
      end

      def execute!
        results = []
        results << create!
        unless container.running?
          results << start!
          results << execute_post_start_scripts!
        end
        results.compact.empty? ? nil : container
      end

      private

        attr_reader :container, :dependant_containers, :cmd, :exec_scripts

        def exec_scripts?
          !container.post_start_scripts.empty? && exec_scripts
        end

        def create!
          return nil if container.exists?
          Create.new(container, cmd: cmd, exec_scripts: exec_scripts).execute!
        end

        def start!
          return nil if !container.startable? || container.running?
          $logger.info "Starting '#{container.name}' container"
          container.docker_container.start!
        end

        def execute_post_start_scripts!
          scripts = container.post_start_scripts
          Exec.new(container, dependant_containers, scripts, 'POST start').execute! if exec_scripts?
        end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
percheron-0.7.6 lib/percheron/actions/start.rb
percheron-0.7.5 lib/percheron/actions/start.rb
percheron-0.7.4 lib/percheron/actions/start.rb
percheron-0.7.3 lib/percheron/actions/start.rb
percheron-0.7.2 lib/percheron/actions/start.rb
percheron-0.7.1 lib/percheron/actions/start.rb
percheron-0.7.0 lib/percheron/actions/start.rb