Sha256: 156d4c7686d1960ac6e0054c3d28a1230e48ce78ffce3a20fe09b25f7d27042a

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module Percheron
  module Actions
    class Start

      include Base

      def initialize(unit, dependant_units: [], cmd: false, exec_scripts: true)
        @unit = unit
        @dependant_units = dependant_units
        @cmd = cmd
        @exec_scripts = exec_scripts
      end

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

      private

        attr_reader :unit, :dependant_units, :cmd, :exec_scripts

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

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

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

        def execute_post_start_scripts!
          scripts = unit.post_start_scripts
          Exec.new(unit, dependant_units, 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.13 lib/percheron/actions/start.rb
percheron-0.7.12 lib/percheron/actions/start.rb
percheron-0.7.11 lib/percheron/actions/start.rb
percheron-0.7.10 lib/percheron/actions/start.rb
percheron-0.7.9 lib/percheron/actions/start.rb
percheron-0.7.8 lib/percheron/actions/start.rb
percheron-0.7.7 lib/percheron/actions/start.rb