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
# 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)
  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]
  )
  Process.exec(*ARGV[2..-1])
end