Module: Baptize::Plugins::Execution
- Defined in:
- lib/baptize/plugins/execution.rb
Instance Method Summary collapse
- #put(buffer, remote, options = {}) ⇒ Object
- #remote_assert(command) ⇒ Object
- #remote_capture(*args) ⇒ Object
- #remote_execute(*args) ⇒ Object
-
#run_locally(cmd) ⇒ Object
logs the command then executes it locally.
- #upload(local, remote, options = {}) ⇒ Object
Instance Method Details
#put(buffer, remote, options = {}) ⇒ Object
60 61 62 |
# File 'lib/baptize/plugins/execution.rb', line 60 def put(buffer, remote, = {}) upload StringIO.new(buffer), remote, end |
#remote_assert(command) ⇒ Object
33 34 35 36 |
# File 'lib/baptize/plugins/execution.rb', line 33 def remote_assert(command) command = Array(command).flatten.map {|c| "#{c} > /dev/null 2> /dev/null" }.join(" && ") call_current_ssh_connection :test, command end |
#remote_capture(*args) ⇒ Object
29 30 31 |
# File 'lib/baptize/plugins/execution.rb', line 29 def remote_capture(*args) call_current_ssh_connection :capture, *args end |
#remote_execute(*args) ⇒ Object
25 26 27 |
# File 'lib/baptize/plugins/execution.rb', line 25 def remote_execute(*args) call_current_ssh_connection :execute, *args end |
#run_locally(cmd) ⇒ Object
logs the command then executes it locally. returns the command output as a string
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/baptize/plugins/execution.rb', line 9 def run_locally(cmd) if fetch(:dry_run) return logger.debug "executing locally: #{cmd.inspect}" end logger.trace "executing locally: #{cmd.inspect}" if logger output_on_stdout = nil elapsed = Benchmark.realtime do output_on_stdout = `#{cmd}` end if $?.to_i > 0 # $? is command exit code (posix style) raise ArgumentError, "Command #{cmd} returned status code #{$?}" end logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger output_on_stdout end |
#upload(local, remote, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/baptize/plugins/execution.rb', line 38 def upload(local, remote, = {}) if fetch(:use_sudo) # perform the transfer in two steps if we're using sudo final = remote remote = "/tmp/baptize_#{File.basename(remote)}" end ssh = fetch(:current_ssh_connection) old_verbosity = nil if fetch(:ssh_verbose) old_verbosity = SSHKit.config.output_verbosity SSHKit.config.output_verbosity = Logger::DEBUG end begin ssh.upload! local, remote, ensure SSHKit.config.output_verbosity = old_verbosity if old_verbosity end if fetch(:use_sudo) remote_execute "mv #{remote.shellescape} #{final.shellescape}" end end |