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.
command | [R] | |
command | [R] | |
options | [R] | |
options | [R] | |
sessions | [R] | |
sessions | [R] |
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:
# 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:
# 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
# File lib/capistrano/command.rb, line 13 13: def self.process(command, sessions, options={}, &block) 14: new(command, sessions, options, &block).process! 15: end
# File lib/capistrano/command.rb, line 13 13: def self.process(command, sessions, options={}, &block) 14: new(command, sessions, options, &block).process! 15: 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.
# 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.
# 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