Class: Capistrano::Command

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

### Classes and Modules

Class Capistrano::Command::Tree

### Attributes

options | [R] |
options | [R] |
sessions | [R] |
sessions | [R] |
tree | [R] |
tree | [R] |

### Public Class methods

new(tree, sessions, options={}, &block)

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 145
    145:     def initialize(tree, sessions, options={}, &block)
    146:       if String === tree
    147:         tree = Tree.new(nil) { |t| t.else(tree, &block) }
    148:       elsif block
    149:         raise ArgumentError, "block given with tree argument"
    150:       end
    151:
    152:       @tree = tree
    153:       @sessions = sessions
    154:       @options = options
    155:       @channels = open_channels
    156:     end

new(tree, sessions, options={}, &block)

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 145
    145:     def initialize(tree, sessions, options={}, &block)
    146:       if String === tree
    147:         tree = Tree.new(nil) { |t| t.else(tree, &block) }
    148:       elsif block
    149:         raise ArgumentError, "block given with tree argument"
    150:       end
    151:
    152:       @tree = tree
    153:       @sessions = sessions
    154:       @options = options
    155:       @channels = open_channels
    156:     end

process(tree, sessions, options={})

[Source]

         # File lib/capistrano/command.rb, line 132
    132:     def self.process(tree, sessions, options={})
    133:       new(tree, sessions, options).process!
    134:     end

process(tree, sessions, options={})

[Source]

         # File lib/capistrano/command.rb, line 132
    132:     def self.process(tree, sessions, options={})
    133:       new(tree, sessions, options).process!
    134:     end

### Public Instance methods

process!()

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 161
    161:     def process!
    162:       loop do
    163:         break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
    164:       end
    165:
    166:       logger.trace "command finished" if logger
    167:
    168:       if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
    169:         commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
    170:         message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ")
    171:         error = CommandError.new("failed: #{message}")
    172:         error.hosts = commands.values.flatten
    173:         raise error
    174:       end
    175:
    176:       self
    177:     end

process!()

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 161
    161:     def process!
    162:       loop do
    163:         break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
    164:       end
    165:
    166:       logger.trace "command finished" if logger
    167:
    168:       if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
    169:         commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
    170:         message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ")
    171:         error = CommandError.new("failed: #{message}")
    172:         error.hosts = commands.values.flatten
    173:         raise error
    174:       end
    175:
    176:       self
    177:     end

stop!()

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

[Source]

         # File lib/capistrano/command.rb, line 181
    181:     def stop!
    182:       @channels.each do |ch|
    183:         ch.close unless ch[:closed]
    184:       end
    185:     end

stop!()

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

[Source]

         # File lib/capistrano/command.rb, line 181
    181:     def stop!
    182:       @channels.each do |ch|
    183:         ch.close unless ch[:closed]
    184:       end
    185:     end

[Validate]