Module: Aptible::CLI::Helpers::Ssh

Included in:
Agent, Database, Operation
Defined in:
lib/aptible/cli/helpers/ssh.rb

Instance Method Summary collapse

Instance Method Details

#connect_to_ssh_portal(operation, *extra_ssh_args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aptible/cli/helpers/ssh.rb', line 5

def connect_to_ssh_portal(operation, *extra_ssh_args)
  with_ssh_cmd(operation) do |base_ssh_cmd|
    ssh_cmd = base_ssh_cmd + extra_ssh_args
    begin
      Kernel.system(*ssh_cmd)
    rescue Interrupt
      # Assuming we have a TTY, there are two cases here. Either SSH
      # itself has a TTY, in which case it is controlling the TTY and
      # the CLI won't be receiving SIGINT when CTRL+C is pressed, or
      # SSH has no TTY, in which case the CLI and SSH are sharing the
      # same process group, and will both receive SIGINT when CTRL+C
      # is pressed and exit accordingly.
      #
      # I'm not sure how this *should* work on Windows, but it appears
      # to work pretty much the same way, except that we'll get an ugly
      # "Terminate batch job (Y/N)?" prompt in the no-TTY-for-SSH case,
      # which we're likely to have a hard time handling.
      #
      # Note that this DOES NOT handle the case where the CLI is sent
      # SIGINT by another process (as opposed to the line discipline).
      # In this case, SSH will continue running in the background. This
      # is something we should fix, but for now this 'simple' fix is
      # enough to addresses the ugly stack trace we show when
      # CTRL+C'ing out of logs.
    end
  end
end

#with_ssh_cmd(operation) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/aptible/cli/helpers/ssh.rb', line 33

def with_ssh_cmd(operation)
  ensure_ssh_dir!
  ensure_config!
  ensure_key!

  operation.with_ssh_cmd(private_key_file) do |cmd, connection|
    yield cmd + common_ssh_args, connection
  end
end