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
# File 'lib/osctld/utils/switch_user.rb', line 6

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

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

Run a command `cmd` within container `ct`

Parameters:

  • ct (Container)
  • cmd (String)

    command to execute in shell

  • 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)


32
33
34
35
36
37
# File 'lib/osctld/utils/switch_user.rb', line 32

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

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