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`



41
42
43
44
45
# File 'lib/osctld/console.rb', line 41

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`



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

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`



48
49
50
51
# File 'lib/osctld/console.rb', line 48

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

.initObject



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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osctld/console.rb', line 21

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

    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



54
55
56
57
58
59
60
# File 'lib/osctld/console.rb', line 54

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

    @cts.delete(ct.id).close_all
  end
end

.socket_path(ct) ⇒ Object

Return path of the socket to the container’s tty0



63
64
65
# File 'lib/osctld/console.rb', line 63

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