Class: Deployer::Executor
- Inherits:
-
Object
- Object
- Deployer::Executor
- Defined in:
- lib/deployer/executor.rb
Instance Attribute Summary collapse
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Instance Method Summary collapse
- #download(source, target, options = {}) ⇒ Object
-
#execute(command, options = {}) ⇒ Object
execute a command on all hosts of a stage commands are expanded with :hostname, :port and :stagename.
- #execute_on(host, command) ⇒ Object
-
#initialize(stage, options = {}) {|_self| ... } ⇒ Executor
constructor
A new instance of Executor.
- #upload(source, target, options = {}) ⇒ Object
Constructor Details
#initialize(stage, options = {}) {|_self| ... } ⇒ Executor
Returns a new instance of Executor.
7 8 9 10 11 |
# File 'lib/deployer/executor.rb', line 7 def initialize(stage, = {}) @stage = stage = yield(self) if block_given? end |
Instance Attribute Details
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
5 6 7 |
# File 'lib/deployer/executor.rb', line 5 def stage @stage end |
Instance Method Details
#download(source, target, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/deployer/executor.rb', line 40 def download(source, target, = {}) log_command("Execute: download via scp #{source} from #{target}", [:comment]) stage.hosts.each_with_index do |host, index| log_host(host, index) result = download_from(host, source, target) log_result(result) result end rescue => e handle_exception(e, ) end |
#execute(command, options = {}) ⇒ Object
execute a command on all hosts of a stage commands are expanded with :hostname, :port and :stagename
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/deployer/executor.rb', line 15 def execute(command, = {}) log_command("Execute: '#{command.strip}'", [:comment]) stage.hosts.each_with_index.map do |host, index| = {hostname: host[:host], stagename: stage.name, port: host[:port]} = command % if != command log_command("Expanded command to #{expanded_command}") end log_host(host, index) result = execute_on(host, ) log_result(result) result end rescue => e handle_exception(e, ) end |
#execute_on(host, command) ⇒ Object
34 35 36 37 38 |
# File 'lib/deployer/executor.rb', line 34 def execute_on(host, command) Net::SSH.start(host[:host], host[:user], port: host[:port]) do |ssh| ssh.exec_sc!(command, verbose?) end end |
#upload(source, target, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/deployer/executor.rb', line 53 def upload(source, target, = {}) log_command("Execute: upload via scp #{source} to #{target}", [:comment]) stage.hosts.each_with_index do |host, index| log_host(host, index) result = upload_on(host, source, target) log_result(result) result end rescue => e handle_exception(e, ) end |