Class: Dockerploy::ShellClient

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerploy/shell_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ShellClient

Returns a new instance of ShellClient.



5
6
7
# File 'lib/dockerploy/shell_client.rb', line 5

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



3
4
5
# File 'lib/dockerploy/shell_client.rb', line 3

def output
  @output
end

Instance Method Details

#command(command) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dockerploy/shell_client.rb', line 9

def command(command)
  Dockerploy.logger.debug sprintf('Running: %s', command)
  IO.popen('-') do |p|
    if p.nil?
      $stderr.close
      exec *command.split(' ')
    end
    @output = p.read
    Dockerploy.logger.debug p.read
  end

  return false if $?.nil?
  result = $?.exitstatus == 0
  if !result && @options[:abort_on_failure]
    Dockerploy.logger.error sprintf('Failed to run: %s', command)
    abort
  end
end