Sha256: 3bb5b0975b4f89d2f54b1b63a5f3ac22ca9f7aec8b68bf1e9a03201bd22dd512

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Percheron
  module Actions
    class Start
      include Base

      def initialize(unit, needed_units: [], cmd: false, exec_scripts: true)
        @unit = unit
        @needed_units = needed_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, :needed_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).execute!
        end

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

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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
percheron-0.8.0 lib/percheron/actions/start.rb