Class: Rays::Service::Remote::SSH
- Inherits:
-
Object
- Object
- Rays::Service::Remote::SSH
- Defined in:
- lib/rays/services/remote.rb
Instance Method Summary collapse
- #copy_from(remote_file, local_file) ⇒ Object
- #copy_to(local_file, remote_file) ⇒ Object
- #exec(command) ⇒ Object
- #host ⇒ Object
-
#initialize(host, port, user) ⇒ SSH
constructor
A new instance of SSH.
- #loop_exec(command) ⇒ Object
- #port ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(host, port, user) ⇒ SSH
Returns a new instance of SSH.
29 30 31 32 33 34 |
# File 'lib/rays/services/remote.rb', line 29 def initialize(host, port, user) @host = host @port = port # TODO: not used for now. @user = user defaults end |
Instance Method Details
#copy_from(remote_file, local_file) ⇒ Object
80 81 82 |
# File 'lib/rays/services/remote.rb', line 80 def copy_from(remote_file, local_file) rays_exec("#{$rays_config.scp} #{user}@#{host}:#{remote_file} #{local_file}") end |
#copy_to(local_file, remote_file) ⇒ Object
76 77 78 |
# File 'lib/rays/services/remote.rb', line 76 def copy_to(local_file, remote_file) rays_exec("#{$rays_config.scp} #{local_file} #{user}@#{host}:#{remote_file}") end |
#exec(command) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/rays/services/remote.rb', line 67 def exec(command) response = "" Net::SSH.start("#{host}", "#{user}") do |ssh| response = ssh.exec!(command) $log.debug(response) end response end |
#host ⇒ Object
36 37 38 39 |
# File 'lib/rays/services/remote.rb', line 36 def host raise RaysException.new(missing_environment_option('ssh', 'host')) if @host.nil? @host end |
#loop_exec(command) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rays/services/remote.rb', line 51 def loop_exec(command) begin Net::SSH.start("#{host}", "#{user}") do |ssh| ssh.open_channel do |channel| channel.on_data do |ch, data| $log.info("<!#{data}!>") end channel.exec command end ssh.loop end rescue SystemExit, Interrupt # Ctrl-c end end |
#port ⇒ Object
41 42 43 44 |
# File 'lib/rays/services/remote.rb', line 41 def port raise RaysException.new(missing_environment_option('ssh', 'port')) if @port.nil? @port end |
#user ⇒ Object
46 47 48 49 |
# File 'lib/rays/services/remote.rb', line 46 def user raise RaysException.new(missing_environment_option('ssh', 'user')) if @user.nil? @user end |