Class: Conjure::Service::RemoteShell
- Inherits:
-
Object
- Object
- Conjure::Service::RemoteShell
- Defined in:
- lib/conjure/service/remote_shell.rb
Class Attribute Summary collapse
-
.ssh_service ⇒ Object
Returns the value of attribute ssh_service.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RemoteShell
constructor
A new instance of RemoteShell.
- #poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
- #run(command, options = {}) ⇒ Object
- #session ⇒ Object
- #with_raw_tty ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RemoteShell
Returns a new instance of RemoteShell.
11 12 13 |
# File 'lib/conjure/service/remote_shell.rb', line 11 def initialize( = {}) = end |
Class Attribute Details
.ssh_service ⇒ Object
Returns the value of attribute ssh_service.
7 8 9 |
# File 'lib/conjure/service/remote_shell.rb', line 7 def ssh_service @ssh_service end |
Instance Method Details
#poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
51 52 53 |
# File 'lib/conjure/service/remote_shell.rb', line 51 def poll_stream(stream, &block) yield stream.sysread(1) if IO.select([stream], nil, nil, 0.01) end |
#run(command, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/conjure/service/remote_shell.rb', line 15 def run(command, = {}) stdout, stderr, exit_status = ["", "", nil] session.open_channel do |channel| channel.request_pty channel.exec command do |c, success| raise "Failed to execute command via SSH" unless success channel.on_data do |c, data| yield data if block_given? stdout << data end channel.on_extended_data { |c, type, data| stderr << data } channel.on_request("exit-status") { |c, data| exit_status = data.read_long } end if [:stream_stdin] channel.on_process do poll_stream(STDIN) { |data| channel.send_data data } end end end if [:stream_stdin] with_raw_tty { session.loop 0.01 } else session.loop end Result.new stdout, stderr, exit_status end |
#session ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/conjure/service/remote_shell.rb', line 42 def session = { :auth_methods => ["publickey"], :paranoid => false, :forward_agent => true, } @session ||= self.class.ssh_service.start [:ip_address], [:username], end |
#with_raw_tty ⇒ Object
55 56 57 58 59 60 |
# File 'lib/conjure/service/remote_shell.rb', line 55 def with_raw_tty system "stty raw -echo" yield ensure system "stty -raw echo" end |