Class: OsCtld::ContainerControl::Frontend

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/container_control/frontend.rb

Overview

Frontend is run from osctld in daemon mode, when it is running as root

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_class, ct) ⇒ Frontend

Returns a new instance of Frontend

Parameters:



12
13
14
15
# File 'lib/osctld/container_control/frontend.rb', line 12

def initialize(command_class, ct)
  @command_class = command_class
  @ct = ct
end

Instance Attribute Details

#command_classClass (readonly)

Returns:

  • (Class)


5
6
7
# File 'lib/osctld/container_control/frontend.rb', line 5

def command_class
  @command_class
end

#ctContainer (readonly)

Returns:



8
9
10
# File 'lib/osctld/container_control/frontend.rb', line 8

def ct
  @ct
end

Instance Method Details

#execute(*args) ⇒ Object

Implement this method

Parameters:

  • args (Array)

    command arguments

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/osctld/container_control/frontend.rb', line 19

def execute(*args)
  raise NotImplementedError
end

#pipe_runner(args: []) ⇒ ContainerControl::Result (protected)

Parameters:

  • args (Array)

    command arguments

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/osctld/container_control/frontend.rb', line 26

def pipe_runner(args: [])
  r, w = IO.pipe

  runner_opts = {
    id: ct.id,
    lxc_home: ct.lxc_home,
    user_home: ct.user.homedir,
    log_file: ct.log_path,
  }

  pid = SwitchUser.fork_and_switch_to(
    ct.user.sysusername,
    ct.user.ugid,
    ct.user.homedir,
    ct.cgroup_path,
    prlimits: ct.prlimits.export,
  ) do
    r.close

    runner = command_class::Runner.new(runner_opts)
    ret = runner.execute(*args)
    w.write(ret.to_json + "\n")

    exit
  end

  w.close

  begin
    ret = JSON.parse(r.readline, symbolize_names: true)
    Process.wait(pid)
    ContainerControl::Result.from_runner(ret)

  rescue EOFError
    Process.wait(pid)
    ContainerControl::Result.new(false, message: 'user runner failed')
  end
end