Sha256: 998682fa9cb7ec059e931407893a9bca325116edc86111b1047129d929712e84

Contents?: true

Size: 717 Bytes

Versions: 3

Compression:

Stored size: 717 Bytes

Contents

module Percheron
  module Actions
    class Shell
      include Base

      DEFAULT_COMMAND = '/bin/sh'
      DOCKER_CLIENT = 'docker'

      def initialize(unit, command: DEFAULT_COMMAND)
        @unit = unit
        @command = command
      end

      def execute!
        exec! if valid?
      end

      private

        attr_reader :unit

        def valid?
          Validators::DockerClient.new.valid?
        end

        def command
          "sh -c '%s'" % @command
        end

        def exec!
          cmd = '%s exec -ti %s %s' % [ DOCKER_CLIENT, unit.full_name, command ]
          $logger.debug %(Executing "#{cmd}" on '#{unit.display_name}' unit)
          system(cmd)
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
percheron-0.7.16 lib/percheron/actions/shell.rb
percheron-0.7.15 lib/percheron/actions/shell.rb
percheron-0.7.14 lib/percheron/actions/shell.rb