Class: OsCtld::ContainerControl::Runner

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

Overview

Runner is run in a forked&execed 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):

  • :pool (String)
  • :id (String)
  • :lxc_home (String)
  • :user_home (String)
  • :log_file (String)
  • :stdin (IO, nil)
  • :stdout (IO)
  • :stderr (IO)


17
18
19
20
21
22
23
24
25
26
# File 'lib/osctld/container_control/runner.rb', line 17

def initialize(**opts)
  @pool = opts[:pool]
  @ctid = opts[:id]
  @lxc_home = opts[:lxc_home]
  @user_home = opts[:user_home]
  @log_file = opts[:log_file]
  @stdin = opts[:stdin]
  @stdout = opts[:stdout]
  @stderr = opts[:stderr]
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

#poolObject (readonly)

Returns the value of attribute pool.



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

def pool
  @pool
end

#stderrObject (readonly, protected)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdinObject (readonly, protected)

Returns the value of attribute stdin.



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

def stdin
  @stdin
end

#stdoutObject (readonly, protected)

Returns the value of attribute stdout.



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

def stdout
  @stdout
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)



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

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

#execute(*args, **kwargs) ⇒ Hash

Implement this method

Parameters:

  • args (Array)

    command arguments

  • kwargs (Array)

    command arguments

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


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

def execute(*args, **kwargs)
  raise NotImplementedError
end

#lxc_ctObject (protected)



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

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

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



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

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

#setup_exec_envObject (protected)



56
57
58
59
60
# File 'lib/osctld/container_control/runner.rb', line 56

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)



62
63
64
65
# File 'lib/osctld/container_control/runner.rb', line 62

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

#system_pathObject (protected)



52
53
54
# File 'lib/osctld/container_control/runner.rb', line 52

def system_path
  SwitchUser::SYSTEM_PATH
end