Module: OsCtld::RunState

Defined in:
lib/osctld/run_state.rb

Defined Under Namespace

Classes: StartConfig

Constant Summary collapse

RUNDIR =
'/run/osctl'.freeze
POOL_DIR =
File.join(RUNDIR, 'pools')
USER_CONTROL_DIR =
File.join(RUNDIR, 'user-control')
SEND_RECEIVE_DIR =
File.join(RUNDIR, 'send-receive')
REPOSITORY_DIR =
File.join(RUNDIR, 'repository')
CONFIG_DIR =
File.join(RUNDIR, 'configs')
OSCTLD_CONFIG_DIR =
File.join(CONFIG_DIR, 'osctld')
LXC_CONFIG_DIR =
File.join(CONFIG_DIR, 'lxc')
APPARMOR_DIR =
File.join(CONFIG_DIR, 'apparmor')
CPU_SCHEDULER_DIR =
File.join(RUNDIR, 'cpu-scheduler')
SHUTDOWN_MARKER =
File.join(RUNDIR, 'shutdown')
CGROUP_VERSION =
File.join(RUNDIR, 'cgroup.version')

Class Method Summary collapse

Class Method Details

.assets(add) ⇒ Object



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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/osctld/run_state.rb', line 42

def self.assets(add)
  add.directory(
    RunState::RUNDIR,
    desc: 'Runtime configuration',
    user: 0,
    group: 0,
    mode: 0o711
  )
  add.directory(
    RunState::POOL_DIR,
    desc: 'Runtime pool configuration',
    user: 0,
    group: 0,
    mode: 0o711
  )
  add.directory(
    RunState::USER_CONTROL_DIR,
    desc: 'Runtime user configuration',
    user: 0,
    group: 0,
    mode: 0o711
  )
  add.directory(
    RunState::SEND_RECEIVE_DIR,
    desc: 'Send/Receive configuration',
    user: SendReceive::UID,
    group: 0,
    mode: 0o100,
    optional: true
  )
  add.directory(
    RunState::REPOSITORY_DIR,
    desc: 'Home directory for the repository user',
    user: Repository::UID,
    group: 0,
    mode: 0o700
  )
  add.directory(
    RunState::CONFIG_DIR,
    desc: 'Global LXC configuration files',
    user: 0,
    group: 0,
    mode: 0o755
  )

  if AppArmor.enabled?
    add.directory(
      RunState::APPARMOR_DIR,
      desc: 'Shared AppArmor files',
      user: 0,
      group: 0,
      mode: 0o755
    )
  end

  SendReceive.assets(add)
  CpuScheduler.assets(add)
end

.createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctld/run_state.rb', line 16

def self.create
  mkdir_p(RUNDIR, 0o711)
  mkdir_p(POOL_DIR, 0o711)
  mkdir_p(USER_CONTROL_DIR, 0o711)
  mkdir_p(SEND_RECEIVE_DIR, 0o100, uid: SendReceive::UID, gid: 0)

  # Bundler needs to have some place to store its temp files
  mkdir_p(REPOSITORY_DIR, 0o700, uid: Repository::UID, gid: 0)

  # LXC configs
  mkdir_p(CONFIG_DIR, 0o755)
  mkdir_p(LXC_CONFIG_DIR, 0o755)

  Lxc.install_lxc_configs(LXC_CONFIG_DIR)

  # AppArmor files
  mkdir_p(APPARMOR_DIR, 0o755)

  mkdir_p(CPU_SCHEDULER_DIR, 0o755)
end

.mkdir_p(path, mode, uid: nil, gid: nil) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/osctld/run_state.rb', line 101

def self.mkdir_p(path, mode, uid: nil, gid: nil)
  begin
    Dir.mkdir(path, mode)
  rescue Errno::EEXIST
    File.chmod(mode, path)
  end

  File.chown(uid, gid, path) if uid && gid
end

.open_start_configRunState::StartConfig



38
39
40
# File 'lib/osctld/run_state.rb', line 38

def self.open_start_config
  StartConfig.new(File.join(OSCTLD_CONFIG_DIR, 'start-config.json'))
end