Module: OsCtld::Utils::SwitchUser

Instance Method Summary collapse

Instance Method Details

#ct_attach(ct, *args) ⇒ Object



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

def ct_attach(ct, *args)
  CGroup.mkpath_all(ct.entry_cgroup_path.split('/'), chown: ct.user.ugid)

  {
    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: ct.entry_cgroup_path,
      prlimits: ct.prlimits.export,
      syslogns_pid: ct.init_pid
    }
  }
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)


35
36
37
38
39
40
# File 'lib/osctld/utils/switch_user.rb', line 35

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

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