Class: OsCtld::ContainerControl::Commands::Exec::Runner
- Includes:
- Utils::Runscript::Runner
- Defined in:
- lib/osctld/container_control/commands/exec.rb
Instance Attribute Summary
Attributes inherited from Runner
#ctid, #log_file, #lxc_home, #stderr, #stdin, #stdout, #user_home
Instance Method Summary collapse
- #exec_run(opts) ⇒ Object protected
- #exec_run_network(opts) ⇒ Object protected
- #exec_running(opts) ⇒ Object protected
-
#execute(mode, opts) ⇒ Integer
Exit status.
Methods included from Utils::Runscript::Runner
#runscript_run, #with_configured_network
Methods inherited from Runner
#error, #initialize, #lxc_ct, #ok, #setup_exec_env, #setup_exec_run_env, #system_path
Constructor Details
This class inherits a constructor from OsCtld::ContainerControl::Runner
Instance Method Details
#exec_run(opts) ⇒ Object (protected)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/osctld/container_control/commands/exec.rb', line 108 def exec_run(opts) pid = Process.fork do STDIN.reopen(stdin) STDOUT.reopen(stdout) STDERR.reopen(stderr) setup_exec_run_env cmd = [ 'lxc-execute', '-P', lxc_home, '-n', ctid, '-o', log_file, '-s', "lxc.environment=PATH=#{system_path.join(':')}", '-s', "lxc.environment=HOME=/root", '-s', "lxc.environment=USER=root", '--', opts[:cmd], ].flatten Process.exec(*cmd) end _, status = Process.wait2(pid) ok(status.exitstatus) end |
#exec_run_network(opts) ⇒ Object (protected)
135 136 137 138 139 140 |
# File 'lib/osctld/container_control/commands/exec.rb', line 135 def exec_run_network(opts) with_configured_network( init_script: opts[:init_script], net_config: opts[:net_config], ) { exec_running(opts) } end |
#exec_running(opts) ⇒ Object (protected)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/osctld/container_control/commands/exec.rb', line 92 def exec_running(opts) pid = lxc_ct.attach( stdin: stdin, stdout: stdout, stderr: stderr, ) do setup_exec_env ENV['HOME'] = '/root' ENV['USER'] = 'root' LXC.run_command(opts[:cmd]) end _, status = Process.wait2(pid) ok(status.exitstatus) end |
#execute(mode, opts) ⇒ Integer
Returns exit status.
87 88 89 |
# File 'lib/osctld/container_control/commands/exec.rb', line 87 def execute(mode, opts) send(:"exec_#{mode}", opts) end |