Sha256: 6ac34550528f33f7eb1993b5bdb1ea440d2c7df44af6e6601f62a9bbee5d8a3b

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'open3'

module Percheron
  module Actions
    class ExecLocal
      include Base

      def initialize(unit, scripts, description)
        @unit = unit
        @scripts = scripts
        @description = description
      end

      def execute!
        results = []
        results << execute_scripts!
        results.compact.empty? ? nil : unit
      end

      private

        attr_reader :unit, :scripts, :description

        def execute_scripts!
          $logger.debug "Executing #{description} scripts '#{scripts.inspect}' locally"
          scripts.each do |script|
            in_working_directory(base_dir) do
              execute_command!('/bin/sh -x %s 2>&1' % [ Pathname.new(File.expand_path(script)) ])
            end
          end
        end

        def execute_command!(command)
          $logger.info "Executing #{description} script '#{command}' locally"
          Open3.popen2e(command) do |_, stdout_stderr, _|
            while (line = stdout_stderr.gets)
              $logger.debug line.strip
            end
          end
        end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
percheron-0.8.1 lib/percheron/actions/exec_local.rb
percheron-0.8.0 lib/percheron/actions/exec_local.rb