Class: OsCtld::ContainerControl::Runner
- Inherits:
-
Object
- Object
- OsCtld::ContainerControl::Runner
- Defined in:
- lib/osctld/container_control/runner.rb
Overview
Runner is run in a forked&execed process and under the container’s user
Direct Known Subclasses
Commands::Exec::Runner, Commands::Freeze::Runner, Commands::GetHostname::Runner, Commands::Mount::Runner, Commands::Reboot::Runner, Commands::Runscript::Runner, Commands::State::Runner, Commands::Stop::Runner, Commands::StopByHalt::Runner, Commands::StopRunit::Runner, Commands::Unfreeze::Runner, Commands::Unmount::Runner, Commands::VethName::Runner, Commands::Wall::Runner, Commands::WithMountns::Runner, Commands::WithRootfs::Runner
Instance Attribute Summary collapse
-
#ctid ⇒ Object
readonly
Returns the value of attribute ctid.
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#lxc_home ⇒ Object
readonly
Returns the value of attribute lxc_home.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#stderr ⇒ Object
readonly
protected
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
protected
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
protected
Returns the value of attribute stdout.
-
#user_home ⇒ Object
readonly
Returns the value of attribute user_home.
Instance Method Summary collapse
- #error(msg) ⇒ Object protected
-
#execute(*args, **kwargs) ⇒ Hash
Implement this method.
-
#initialize(**opts) ⇒ Runner
constructor
A new instance of Runner.
- #lxc_ct ⇒ Object protected
- #ok(out = nil) ⇒ Object protected
- #setup_exec_env ⇒ Object protected
- #setup_exec_run_env ⇒ Object protected
- #system_path ⇒ Object protected
Constructor Details
#initialize(**opts) ⇒ Runner
Returns a new instance of Runner.
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
#ctid ⇒ Object (readonly)
Returns the value of attribute ctid.
6 7 8 |
# File 'lib/osctld/container_control/runner.rb', line 6 def ctid @ctid end |
#log_file ⇒ Object (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_home ⇒ Object (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 |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
6 7 8 |
# File 'lib/osctld/container_control/runner.rb', line 6 def pool @pool end |
#stderr ⇒ Object (readonly, protected)
Returns the value of attribute stderr.
38 39 40 |
# File 'lib/osctld/container_control/runner.rb', line 38 def stderr @stderr end |
#stdin ⇒ Object (readonly, protected)
Returns the value of attribute stdin.
38 39 40 |
# File 'lib/osctld/container_control/runner.rb', line 38 def stdin @stdin end |
#stdout ⇒ Object (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_home ⇒ Object (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
32 33 34 |
# File 'lib/osctld/container_control/runner.rb', line 32 def execute(*args, **kwargs) raise NotImplementedError end |
#lxc_ct ⇒ Object (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_env ⇒ Object (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_env ⇒ Object (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_path ⇒ Object (protected)
52 53 54 |
# File 'lib/osctld/container_control/runner.rb', line 52 def system_path SwitchUser::SYSTEM_PATH end |