4
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/mimas/server/console.rb', line 4
def start_console(site)
console_command = site.console
system('stty cbreak -echo')
Net::SSH.start(host, user) do |session|
session.open_channel do |channel|
channel.request_pty do
channel.exec("cd #{current_path(site)} && /bin/bash -lc #{console_command}") do
channel.on_data do |_, data|
$stdout.print(data) if data
end
channel.on_extended_data do |_, data|
$stdout.print(data) if data
end
session.listen_to($stdin) do |stdin|
input = stdin.readpartial(1024)
channel.send_data(input) unless input.empty?
end
end
end
end
session.loop
end
ensure
system('stty sane')
end
|