Class: OsCtld::Cli::Exec

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

Class Method Summary collapse

Class Method Details

.runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/osctld/cli/exec.rb', line 5

def self.run
  if ARGV.size < 3 || ARGV[1] != '--'
    warn 'Usage: <settings file> -- <command> [arguments...]'
    exit(false)
  end

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

  cfg = JSON.parse(File.read(ARGV[0]), symbolize_names: true)

  SwitchUser.apply_prlimits(Process.pid, cfg[:prlimits])
  SwitchUser.switch_to(
    cfg[:user],
    cfg[:ugid],
    cfg[:homedir],
    cfg[:cgroup_path],
    syslogns_pid: cfg[:syslogns_pid]
  )
  Process.exec(*ARGV[2..])
end