Class Capistrano::Command
In: lib/capistrano/command.rb
lib/capistrano/command.rb
Parent: Object

This class encapsulates a single command to be executed on a set of remote machines, in parallel.

Methods

new   new   process   process   process!   process!   stop!   stop!  

Included Modules

Processable Processable

Attributes

command  [R] 
command  [R] 
options  [R] 
options  [R] 
sessions  [R] 
sessions  [R] 

Public Class methods

Instantiates a new command object. The command must be a string containing the command to execute. sessions is an array of Net::SSH session instances, and options must be a hash containing any of the following keys:

  • logger: (optional), a Capistrano::Logger instance
  • data: (optional), a string to be sent to the command via it‘s stdin
  • env: (optional), a string or hash to be interpreted as environment variables that should be defined for this command invocation.

[Source]

    # File lib/capistrano/command.rb, line 26
26:     def initialize(command, sessions, options={}, &block)
27:       @command = command.strip.gsub(/\r?\n/, "\\\n")
28:       @sessions = sessions
29:       @options = options
30:       @callback = block
31:       @channels = open_channels
32:     end

Instantiates a new command object. The command must be a string containing the command to execute. sessions is an array of Net::SSH session instances, and options must be a hash containing any of the following keys:

  • logger: (optional), a Capistrano::Logger instance
  • data: (optional), a string to be sent to the command via it‘s stdin
  • env: (optional), a string or hash to be interpreted as environment variables that should be defined for this command invocation.

[Source]

    # File lib/capistrano/command.rb, line 26
26:     def initialize(command, sessions, options={}, &block)
27:       @command = command.strip.gsub(/\r?\n/, "\\\n")
28:       @sessions = sessions
29:       @options = options
30:       @callback = block
31:       @channels = open_channels
32:     end

[Source]

    # File lib/capistrano/command.rb, line 13
13:     def self.process(command, sessions, options={}, &block)
14:       new(command, sessions, options, &block).process!
15:     end

[Source]

    # File lib/capistrano/command.rb, line 13
13:     def self.process(command, sessions, options={}, &block)
14:       new(command, sessions, options, &block).process!
15:     end

Public Instance methods

Processes the command in parallel on all specified hosts. If the command fails (non-zero return code) on any of the hosts, this will raise a Capistrano::CommandError.

[Source]

    # File lib/capistrano/command.rb, line 37
37:     def process!
38:       loop do
39:         break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
40:       end
41: 
42:       logger.trace "command finished" if logger
43: 
44:       if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
45:         hosts = failed.map { |ch| ch[:server] }
46:         error = CommandError.new("command #{command.inspect} failed on #{hosts.join(',')}")
47:         error.hosts = hosts
48:         raise error
49:       end
50: 
51:       self
52:     end

Processes the command in parallel on all specified hosts. If the command fails (non-zero return code) on any of the hosts, this will raise a Capistrano::CommandError.

[Source]

    # File lib/capistrano/command.rb, line 37
37:     def process!
38:       loop do
39:         break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
40:       end
41: 
42:       logger.trace "command finished" if logger
43: 
44:       if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
45:         hosts = failed.map { |ch| ch[:server] }
46:         error = CommandError.new("command #{command.inspect} failed on #{hosts.join(',')}")
47:         error.hosts = hosts
48:         raise error
49:       end
50: 
51:       self
52:     end

Force the command to stop processing, by closing all open channels associated with this command.

[Source]

    # File lib/capistrano/command.rb, line 56
56:     def stop!
57:       @channels.each do |ch|
58:         ch.close unless ch[:closed]
59:       end
60:     end

Force the command to stop processing, by closing all open channels associated with this command.

[Source]

    # File lib/capistrano/command.rb, line 56
56:     def stop!
57:       @channels.each do |ch|
58:         ch.close unless ch[:closed]
59:       end
60:     end

[Validate]