mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Set :actor key on SSH channel instances. Add Actor.default_io_proc
git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3381 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
fb521454f6
commit
1320e07f8c
3 changed files with 22 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
|||
*0.11.0* *SVN*
|
||||
|
||||
* Added Actor.default_io_proc
|
||||
|
||||
* Set :actor key on SSH channel instances
|
||||
|
||||
|
||||
*0.10.0* (January 2nd, 2006)
|
||||
|
||||
* Handle ssh password prompts like "someone's password:"
|
||||
|
|
|
@ -29,12 +29,18 @@ module SwitchTower
|
|||
attr_accessor :connection_factory
|
||||
attr_accessor :command_factory
|
||||
attr_accessor :transfer_factory
|
||||
attr_accessor :default_io_proc
|
||||
end
|
||||
|
||||
self.connection_factory = DefaultConnectionFactory
|
||||
self.command_factory = Command
|
||||
self.transfer_factory = Transfer
|
||||
|
||||
self.default_io_proc = Proc.new do |ch, stream, out|
|
||||
level = out == :error ? :important : :info
|
||||
ch[:actor].logger.send(level, out, "#{stream} :: #{ch[:host]}")
|
||||
end
|
||||
|
||||
# The configuration instance associated with this actor.
|
||||
attr_reader :configuration
|
||||
|
||||
|
@ -105,7 +111,7 @@ module SwitchTower
|
|||
# Define a new task for this actor. The block will be invoked when this
|
||||
# task is called.
|
||||
def define_task(name, options={}, &block)
|
||||
@tasks[name] = Task.new(name, options)
|
||||
@tasks[name] = (options[:task_class] || Task).new(name, options)
|
||||
define_method(name) do
|
||||
send "before_#{name}" if respond_to? "before_#{name}"
|
||||
logger.trace "executing task #{name}"
|
||||
|
@ -129,10 +135,7 @@ module SwitchTower
|
|||
#
|
||||
# If +pretend+ mode is active, this does nothing.
|
||||
def run(cmd, options={}, &block)
|
||||
block ||= Proc.new do |ch, stream, out|
|
||||
logger.debug(out, "#{stream} :: #{ch[:host]}")
|
||||
end
|
||||
|
||||
block ||= default_io_proc
|
||||
logger.debug "executing #{cmd.strip.inspect}"
|
||||
|
||||
execute_on_servers(options) do |servers|
|
||||
|
@ -176,9 +179,7 @@ module SwitchTower
|
|||
# the sudo password (if required) is the same as the password for logging
|
||||
# in to the server.
|
||||
def sudo(command, options={}, &block)
|
||||
block ||= Proc.new do |ch, stream, out|
|
||||
logger.debug(out, "#{stream} :: #{ch[:host]}")
|
||||
end
|
||||
block ||= default_io_proc
|
||||
|
||||
# in order to prevent _each host_ from prompting when the password was
|
||||
# wrong, let's track which host prompted first and only allow subsequent
|
||||
|
@ -320,6 +321,11 @@ module SwitchTower
|
|||
task_call_frames.last.rollback = block
|
||||
end
|
||||
|
||||
# An instance-level reader for the class' #default_io_proc attribute.
|
||||
def default_io_proc
|
||||
self.class.default_io_proc
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def metaclass
|
||||
|
|
|
@ -56,6 +56,7 @@ module SwitchTower
|
|||
@servers.map do |server|
|
||||
@actor.sessions[server].open_channel do |channel|
|
||||
channel[:host] = server
|
||||
channel[:actor] = @actor # so callbacks can access the actor instance
|
||||
channel.request_pty :want_reply => true
|
||||
|
||||
channel.on_success do |ch|
|
||||
|
|
Loading…
Reference in a new issue