Class: OsCtld::ContainerControl::Commands::WithMountns::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/osctld/container_control/commands/with_mountns.rb

Instance Attribute Summary

Attributes inherited from Runner

#ctid, #log_file, #lxc_home, #pool, #stderr, #stdin, #stdout, #user_home

Instance Method Summary collapse

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

#execute(opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :ns_pid (Integer)
  • :chroot (String, nil)
  • :switch_to_system (Boolean)
  • :block (Proc)


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
# File 'lib/osctld/container_control/commands/with_mountns.rb', line 41

def execute(opts)
  sys = OsCtl::Lib::Sys.new
  sys.setns_path(
    File.join('/proc', opts[:ns_pid].to_s, 'ns', 'mnt'),
    OsCtl::Lib::Sys::CLONE_NEWNS
  )

  if opts[:chroot]
    sys.chroot(opts[:chroot])

    # After chroot, we can no longer access syslog logger. Log to stdout
    # instead, which will be picked up by osctld supervisor and sent to
    # syslog from there.
    OsCtl::Lib::Logger.setup(:stdout)
  end

  if opts[:switch_to_system]
    SwitchUser.switch_to_system(
      '',
      opts[:ctrc].ct.root_host_uid,
      opts[:ctrc].ct.root_host_gid,
      '/'
    )
  end

  ok(opts[:block].call)
end