Class: OsCtld::ContainerControl::Commands::Runscript::Frontend
- Includes:
- Utils::Runscript::Frontend
- Defined in:
- lib/osctld/container_control/commands/runscript.rb
Constant Summary
Constants included from Utils::Runscript::Frontend
Utils::Runscript::Frontend::TRANSIENT_CLEANUP_TIMEOUT
Constants inherited from Frontend
Instance Attribute Summary
Attributes inherited from Frontend
Instance Method Summary collapse
- #copy_script(src, stdin) ⇒ Object protected
-
#execute(opts) ⇒ Integer
Exit status.
Methods included from Utils::Runscript::Frontend
#add_network_opts, #cleanup_init_script, #init_script, #runscript_mode, #sync_state_after_transient_run, #unlink_file
Methods inherited from Frontend
#cleanup_runner_cgroup, #exec_runner, #fork_runner, #initialize, #reap_failed_runner, #runner_result, #write_runner_failure
Constructor Details
This class inherits a constructor from OsCtld::ContainerControl::Frontend
Instance Method Details
#copy_script(src, stdin) ⇒ Object (protected)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/osctld/container_control/commands/runscript.rb', line 75 def copy_script(src, stdin) script = Tempfile.create(['.runscript', '.sh'], ct.get_run_conf.rootfs) script.chmod(0o500) if src.nil? IO.copy_stream(stdin, script) stdin.close else File.open(src, 'r') { |f| IO.copy_stream(f, script) } end script.close script end |
#execute(opts) ⇒ Integer
Returns exit status.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/osctld/container_control/commands/runscript.rb', line 27 def execute(opts) runner_opts = { args: opts[:args] } mode = runscript_mode(run: opts[:run], network: opts[:network]) add_network_opts(runner_opts) if opts[:network] script = copy_script(opts[:script], opts[:stdin]) runner_opts[:script] = File.join('/', File.basename(script.path)) if %i[run run_network].include?(mode) ct.ensure_run_conf # Remove any left-over temporary mounts ct.mounts.prune # Pre-start distconfig hook DistConfig.run(ct.run_conf, :pre_start) end ret = exec_runner( args: [mode, runner_opts], stdin: opts[:script].nil? ? nil : opts[:stdin], stdout: opts[:stdout], stderr: opts[:stderr], switch_extra_namespaces: mode != :running, transient_network: mode == :run_network, reset_subtree_control: mode != :running ) ret.ok? ? ret.data : ret ensure begin sync_state_after_transient_run(mode) if mode ensure if script script.close unlink_file(script.path) end cleanup_init_script end end |