Sha256: fedfaa3f99a6ef78cf1b48133871b77aae0a906fe2d0f16385a6708b9af58072

Contents?: true

Size: 750 Bytes

Versions: 2

Compression:

Stored size: 750 Bytes

Contents

module Percheron
  module Actions
    class Shell
      include Base

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

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

      def execute!
        exec! if valid?
      end

      private

        attr_reader :unit, :raw_command

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

        def command
          "sh -c '%s'" % [ raw_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

2 entries across 2 versions & 1 rubygems

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