Class: OsCtld::ContainerControl::Runner

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

Overview

Runner is run in a forked process and under the container's user

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • opts (Hash)

    container options

Options Hash (opts):

  • :lxc_home (String)
  • :user_home (String)
  • :log_file (String)


12
13
14
15
16
17
# File 'lib/osctld/container_control/runner.rb', line 12

def initialize(opts)
  @ctid = opts[:id]
  @lxc_home = opts[:lxc_home]
  @user_home = opts[:user_home]
  @log_file = opts[:log_file]
end

Instance Attribute Details

#ctidObject (readonly)

Returns the value of attribute ctid.



6
7
8
# File 'lib/osctld/container_control/runner.rb', line 6

def ctid
  @ctid
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



6
7
8
# File 'lib/osctld/container_control/runner.rb', line 6

def log_file
  @log_file
end

#lxc_homeObject (readonly)

Returns the value of attribute lxc_home.



6
7
8
# File 'lib/osctld/container_control/runner.rb', line 6

def lxc_home
  @lxc_home
end

#user_homeObject (readonly)

Returns the value of attribute user_home.



6
7
8
# File 'lib/osctld/container_control/runner.rb', line 6

def user_home
  @user_home
end

Instance Method Details

#error(msg) ⇒ Object (protected)



31
32
33
# File 'lib/osctld/container_control/runner.rb', line 31

def error(msg)
  {status: false, message: msg}
end

#execute(*args) ⇒ Hash

Implement this method

Parameters:

  • args (Array)

    command arguments

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/osctld/container_control/runner.rb', line 22

def execute(*args)
  raise NotImplementedError
end

#lxc_ctObject (protected)



35
36
37
# File 'lib/osctld/container_control/runner.rb', line 35

def lxc_ct
  @lxc_ct ||= LXC::Container.new(ctid, lxc_home)
end

#ok(out = nil) ⇒ Object (protected)



27
28
29
# File 'lib/osctld/container_control/runner.rb', line 27

def ok(out = nil)
  {status: true, output: out}
end

#setup_exec_envObject (protected)



43
44
45
46
47
# File 'lib/osctld/container_control/runner.rb', line 43

def setup_exec_env
  ENV.delete_if { |k, _| k != 'TERM' }
  ENV['PATH'] = system_path.join(':')
  ENV['HOME'] = user_home
end

#setup_exec_run_envObject (protected)



49
50
51
52
# File 'lib/osctld/container_control/runner.rb', line 49

def setup_exec_run_env
  setup_exec_env
  ENV['PATH'] = ['/run/wrappers/bin', ENV['PATH']].join(':')
end

#system_pathObject (protected)



39
40
41
# File 'lib/osctld/container_control/runner.rb', line 39

def system_path
  SwitchUser::SYSTEM_PATH
end