Class: OsCtld::UserControl::Commands::CtPreStart

Inherits:
Base show all
Includes:
OsCtl::Lib::Utils::Log
Defined in:
lib/osctld/user_control/commands/ct_pre_start.rb

Instance Attribute Summary

Attributes inherited from Base

#user

Attributes inherited from Commands::Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

handle, #initialize, #owns_ct?, run

Methods inherited from Commands::Base

#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::UserControl::Commands::Base

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/osctld/user_control/commands/ct_pre_start.rb', line 10

def execute
  ct = DB::Containers.find(opts[:id], opts[:pool])
  return error('container not found') unless ct
  return error('access denied') unless owns_ct?(ct)

  ct.starting

  # Mount datasets
  ct.mount(force: true)

  # Load AppArmor profile
  ct.apparmor.setup

  # Configure CGroups
  ret = call_cmd(
    Commands::Container::CGParamApply,
    id: ct.id,
    pool: ct.pool.name,
    manipulation_lock: 'ignore',
  )
  return ret unless ret[:status]

  # Configure devices cgroup
  ct.devices.apply

  # Prepared shared mount directory
  ct.mounts.shared_dir.create

  # Configure hostname
  DistConfig.run(ct, :set_hostname) if ct.hostname

  # Configure network within the CT
  ct.dist_configure_network

  # DNS resolvers
  DistConfig.run(ct, :dns_resolvers) if ct.dns_resolvers

  # User-defined hook
  Container::Hook.run(ct, :pre_start)

  ok

rescue HookFailed => e
  error(e.message)
end