Module: OsCtld::Console

Includes:
OsCtl::Lib::Utils::Log
Defined in:
lib/osctld/console.rb

Overview

Module holding functions and classes working with container consoles/ttys

Defined Under Namespace

Classes: Console, Container, TTY

Class Method Summary collapse

Class Method Details

.client(ct, n, io) ⇒ Object

Add client socket io for container ct to tty n



51
52
53
54
55
# File 'lib/osctld/console.rb', line 51

def self.client(ct, n, io)
  @mutex.synchronize do
    container(ct).add_client(n, io)
  end
end

.connect_tty0(ct, pid) ⇒ Object

Connect to tty0 of container ct



23
24
25
26
27
# File 'lib/osctld/console.rb', line 23

def self.connect_tty0(ct, pid)
  @mutex.synchronize do
    container(ct).connect_tty0(pid, socket_path(ct))
  end
end

.container(ct) ⇒ Object

Return Container for ct



58
59
60
61
62
# File 'lib/osctld/console.rb', line 58

def self.container(ct)
  key = container_key(ct)
  @cts[key] = Container.new(ct) unless @cts.has_key?(key)
  @cts[key]
end

.expect_tty0(ct) ⇒ Object

Reserve exit cleanup for the wrapper even if its console cannot connect.



14
15
16
# File 'lib/osctld/console.rb', line 14

def self.expect_tty0(ct)
  @mutex.synchronize { container(ct).expect_tty0(ct.run_conf) }
end

.handles_run?(ct, run_conf) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/osctld/console.rb', line 18

def self.handles_run?(ct, run_conf)
  @mutex.synchronize { @cts[container_key(ct)]&.handles_run?(run_conf) || false }
end

.init ⇒ Object



8
9
10
11
# File 'lib/osctld/console.rb', line 8

def self.init
  @mutex = Mutex.new
  @cts = {}
end

.reconnect_tty0(ct) ⇒ Object

Reconnect tty0 pipes on osctld restart



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/osctld/console.rb', line 30

def self.reconnect_tty0(ct)
  @mutex.synchronize do
    log(:info, ct, 'Reopening TTY0')
    container(ct).expect_tty0(ct.run_conf)

    socket = socket_path(ct)

    unless File.exist?(socket)
      log(
        :warn,
        ct,
        "Socket '#{socket}' for tty0 not found, console will not work"
      )
      return
    end

    container(ct).connect_tty0(nil, socket)
  end
end

.remove(ct) ⇒ Object

Remove Container for ct and close all ttys



65
66
67
68
69
70
71
72
# File 'lib/osctld/console.rb', line 65

def self.remove(ct)
  @mutex.synchronize do
    key = container_key(ct)
    next unless @cts.has_key?(key)

    @cts.delete(key).close_all
  end
end

.socket_path(ct) ⇒ Object

Return path of the socket to the container's tty0



75
76
77
# File 'lib/osctld/console.rb', line 75

def self.socket_path(ct)
  File.join(ct.pool.console_dir, ct.id, 'tty0.sock')
end