Class: OsCtld::Cli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/cli/runner.rb

Class Method Summary collapse

Class Method Details

.runObject



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
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctld/cli/runner.rb', line 6

def self.run
  if ARGV.length > 0
    warn "Usage: #{$0}"
    exit(false)
  end

  OsCtl::Lib::Logger.setup(:none)
  CGroup.init

  cfg = JSON.parse(STDIN.readline, symbolize_names: true)

  Process.setproctitle(
    "osctld: #{cfg[:pool]}:#{cfg[:id]} runner:#{cfg[:name].downcase}"
  )

  ret = IO.new(cfg[:return])
  stdin = cfg[:stdin] && IO.new(cfg[:stdin])
  stdout = IO.new(cfg[:stdout])
  stderr = IO.new(cfg[:stderr])

  [ret, stdin, stdout, stderr].compact.each do |io|
    io.close_on_exec = true
  end

  runner = OsCtld::ContainerControl::Commands.const_get(cfg[:name])::Runner.new(
    id: cfg[:id],
    lxc_home: cfg[:lxc_home],
    user_home: cfg[:user_home],
    log_file: cfg[:log_file],
    stdin: stdin,
    stdout: stdout,
    stderr: stderr,
  )
  val = runner.execute(*cfg[:args], **cfg[:kwargs])
  ret.puts(val.to_json)
end