Module: OsCtld::Utils::SwitchUser

Instance Method Summary collapse

Instance Method Details

#ct_attach(ct, *args, syslogns_tag: nil, cgroup_path: ct.attach_cgroup_path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/osctld/utils/switch_user.rb', line 6

def ct_attach(ct, *args, syslogns_tag: nil, cgroup_path: ct.attach_cgroup_path)
  CGroup.mkpath_all(
    cgroup_path.split('/'),
    chown: ct.user.ugid,
    delegate_existing: false
  )

  {
    cmd: ::OsCtld.bin('osctld-ct-exec'),
    args: args.map(&:to_s),
    env: ENV.select { |k, _v| k.start_with?('BUNDLE') || k.start_with?('GEM') }.to_h,
    settings: {
      user: ct.user.sysusername,
      ugid: ct.user.ugid,
      homedir: ct.user.homedir,
      cgroup_path:,
      syslogns_tag:,
      prlimits: ct.prlimits.export
    }
  }
end

#ct_syscmd(ct, cmd, opts = {}) ⇒ OsCtl::Lib::SystemCommandResult

Run a command cmd within container ct

Parameters:

  • ct (Container)
  • cmd (Array<String>) —

    command to execute

  • opts (Hash) (defaults to: {}) —

    options

Options Hash (opts):

  • :stdin (IO)
  • :stdout (IO)
  • :stderr (IO)
  • :run (Boolean) —

    run the container if it is stopped?

  • :network (Boolean) —

    setup network if the container is run?

  • :valid_rcs (Array<Integer>, Symbol)

Returns:

  • (OsCtl::Lib::SystemCommandResult)


39
40
41
42
43
44
# File 'lib/osctld/utils/switch_user.rb', line 39

def ct_syscmd(ct, cmd, opts = {})
  opts[:valid_rcs] ||= []
  log(:work, ct, cmd)

  ContainerControl::Commands::Syscmd.run!(ct, cmd, opts)
end